{-# LANGUAGE CPP #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE RankNTypes #-}

{-# OPTIONS_GHC -O2 #-}

import Control.Applicative
import Control.Monad
import Data.Bits
import Data.Char
import Data.Functor
import Data.Maybe
import Data.Monoid hiding ((<>))
import Data.Semigroup

import qualified Data.ByteString.Lazy.Char8 as BS

#if __GLASGOW_HASKELL__ >= 713
import Control.Monad.Trans.State
import Control.Monad.Trans.Reader
import Data.Functor.Identity
#endif

import Control.Monad.ST.Safe
import Data.Function
import Data.Array.IArray
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import Data.Int
import Data.STRef
import qualified Data.List as List
import qualified Data.Array as Arr

-- {{{ Functors

#if __GLASGOW_HASKELL__ < 713
newtype Identity a = Identity {runIdentity :: a}

instance Functor Identity where
  fmap f (Identity x) = Identity $ f x
#endif

-- }}}

-- {{{ Monads

#if __GLASGOW_HASKELL__ < 713
newtype Reader a b = Reader {runReader :: a -> b}
newtype State s a = State {runState :: s -> (a, s)}

instance Functor (Reader a) where
  fmap f =  Reader . (f . ). runReader
  {-# INLINE fmap #-}

instance Applicative (Reader a) where
  pure = Reader . const
  {-# INLINE pure #-}
  a <*> b = Reader f'
    where
      f1 = runReader a
      f2 = runReader b
      f' = \p -> (f1 p) (f2 p)
  {-# INLINE (<*>) #-}

instance Monad (Reader a) where
  r1 >>= r2 = Reader $ \a -> runReader (r2 $ runReader r1 a) a
  {-# INLINE (>>=) #-}
  return = pure

ask :: Reader a a
ask = Reader id
{-# INLINE ask #-}
local :: (a -> a) -> Reader a b -> Reader a b
local f r = let f' = (runReader r) . f in Reader f'
{-# INLINE local #-}

instance Functor (State s) where
  fmap f st = State $ \s -> let (a, s') = runState st s in (f a, s')

instance Applicative (State s) where
  pure = State . (,)
  {-# INLINE pure #-}
  s1 <*> s2 = State $ \s ->
    let (f, s') = runState s1 s
        (a, s'') = runState s2 s'
    in (f a, s'')

instance Monad (State s) where
  s1 >>= ms2 = State $ \s ->
    let (a, s') = runState s1 s
    in runState (ms2 a) s'
  return = pure

put :: s -> State s ()
put = State . const . ((,) ())
{-# INLINE put #-}
get :: State s s
get = State $ \s -> (s, s)
{-# INLINE get #-}
execState :: State s a -> s -> s
execState st s0 = snd $ runState st s0
#endif

-- }}}

-- {{{ Lens

type CylLens a s b t = forall f. Functor f => (a -> f s) -> b -> f t
type CylLens' a b = CylLens a a b b
lens :: (b -> a) -> (b -> s -> t) -> CylLens a s b t
lens r w g b = w b <$> g (r b)
{-# INLINE lens #-}
iso :: (a -> b) -> (b -> a) -> CylLens' a b
iso f f' = let f'' _ a = f a in lens f' f''
{-# INLINE iso #-}
lensGet :: CylLens a s b t -> b -> a
lensGet lens = getConst . lens Const
{-# INLINE lensGet #-}
lensSet :: CylLens a s b t -> b -> s -> t
lensSet lens b s = runIdentity $ lens (Identity . const s) b
{-# INLINE lensSet #-}

#if __GLASGOW_HASKELL__ < 713
infix 1 &
#endif

infix 8 ^.
infix 4 .=, %=
infixr 4 .~, %~

#if __GLASGOW_HASKELL__ < 713
(&) :: a -> (a -> b) -> b
a & f = f a
{-# INLINE (&) #-}
#endif

(^.) :: b -> CylLens a s b t -> a
b ^. lens = lensGet lens b
{-# INLINE (^.) #-}
(%~) :: CylLens a s b t -> (a -> s) -> (b -> t)
(lens %~ f) b = lensSet lens b (f $ lensGet lens b)
{-# INLINE (%~) #-}
(.~) :: CylLens a s b t -> s -> (b -> t)
(lens .~ v) b = lensSet lens b v
{-# INLINE (.~) #-}
(.=) :: CylLens a a' s s -> a' -> State s ()
lens .= v = do {s <- get; put $ s & lens .~ v}
{-# INLINE (.=) #-}
(%=) :: CylLens a a' s s -> (a -> a') -> State s ()
lens %= f = do {s <- get; put $ s & lens %~ f}
{-# INLINE (%=) #-}
view :: CylLens a a' s s' -> Reader s a
view l = ask >>= return . (^. l)
use :: CylLens a a' s s' -> State s a
use l = get >>= return . (^. l)
zoom :: CylLens' s' s -> State s' c -> State s c
zoom l m = do
  s' <- use l
  let (c, s'') = runState m s'
  l .= s''
  return c

-- }}}

-- {{{ Common used lens

class Has1 m a | m -> a where
  _1 :: CylLens' a m

class Has2 m a | m -> a where
  _2 :: CylLens' a m

class Has3 m a | m -> a where
  _3 :: CylLens' a m

class Has4 m a | m -> a where
  _4 :: CylLens' a m

class Has5 m a | m -> a where
  _5 :: CylLens' a m

class Has6 m a | m -> a where
  _6 :: CylLens' a m

instance Has1 ((,) a b) a where
  _1 = lens fst $ \(a, b) c -> (c, b)
  {-# INLINE _1 #-}

instance Has1 ((,,) a b c) a where
  _1 = lens (\(a, _, _) -> a) $ \(a, b, c) d -> (d, b, c)
  {-# INLINE _1 #-}

instance Has1 ((,,,) a b c d) a where
  _1 = lens (\(a, _, _, _) -> a) $ \(a, b, c, d) e -> (e, b, c, d)
  {-# INLINE _1 #-}

instance Has1 ((,,,,) a b c d e) a where
  _1 = lens (\(a, _, _, _, _) -> a) $ \(a, b, c, d, e) f -> (f, b, c, d, e)
  {-# INLINE _1 #-}

instance Has1 ((,,,,,) a b c d e f) a where
  _1 = lens (\(a, _, _, _, _, _) -> a) $ \(a, b, c, d, e, f) g -> (g, b, c, d, e, f)
  {-# INLINE _1 #-}

instance Has2 ((,) a b) b where
  _2 = lens snd $ \(a, b) c -> (a, c)
  {-# INLINE _2 #-}

instance Has2 ((,,) a b c) b where
  _2 = lens (\(_, b, _) -> b) $ \(a, b, c) d -> (a, d, c)
  {-# INLINE _2 #-}

instance Has2 ((,,,) a b c d) b where
  _2 = lens (\(_, b, _, _) -> b) $ \(a, b, c, d) e -> (a, e, c, d)
  {-# INLINE _2 #-}

instance Has2 ((,,,,) a b c d e) b where
  _2 = lens (\(_, b, _, _, _) -> b) $ \(a, b, c, d, e) f -> (a, f, c, d, e)
  {-# INLINE _2 #-}

instance Has2 ((,,,,,) a b c d e f) b where
  _2 = lens (\(_, b, _, _, _, _) -> b) $ \(a, b, c, d, e, f) g -> (a, g, c, d, e, f)
  {-# INLINE _2 #-}

instance Has3 ((,,) a b c) c where
  _3 = lens (\(_, _, c) -> c) $ \(a, b, c) d -> (a, b, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,) a b c d) c where
  _3 = lens (\(_, _, c, _) -> c) $ \(a, b, c, d) e -> (a, b, e, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,,) a b c d e) c where
  _3 = lens (\(_, _, c, _, _) -> c) $ \(a, b, c, d, e) f -> (a, b, f, d, e)
  {-# INLINE _3 #-}

instance Has3 ((,,,,,) a b c d e f) c where
  _3 = lens (\(_, _, c, _, _, _) -> c) $ \(a, b, c, d, e, f) g -> (a, b, g, d, e, f)
  {-# INLINE _3 #-}

instance Has4 ((,,,) a b c d) d where
  _4 = lens (\(_, _, _, d) -> d) $ \(a, b, c, d) e -> (a, b, c, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,) a b c d e) d where
  _4 = lens (\(_, _, _, d, _) -> d) $ \(a, b, c, d, e) f -> (a, b, c, f, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,,) a b c d e f) d where
  _4 = lens (\(_, _, _, d, _, _) -> d) $ \(a, b, c, d, e, f) g -> (a, b, c, g, e, f)
  {-# INLINE _4 #-}

instance Has5 ((,,,,) a b c d e) e where
  _5 = lens (\(_, _, _, _, e) -> e) $ \(a, b, c, d, e) f -> (a, b, c, d, f)
  {-# INLINE _5 #-}

instance Has5 ((,,,,,) a b c d e f) e where
  _5 = lens (\(_, _, _, _, e, _) -> e) $ \(a, b, c, d, e, f) g -> (a, b, c, d, g, f)
  {-# INLINE _5 #-}

instance Has6 ((,,,,,) a b c d e f) f where
  _6 = lens (\(_, _, _, _, _, f) -> f) $ \(a, b, c, d, e, f) g -> (a, b, c, d, e, g)
  {-# INLINE _6 #-}

-- }}}

-- {{{ Handy IO

type StringReader a = State BS.ByteString a

readContents :: StringReader a -> IO a
readContents reader = do
  contents <- BS.getContents
  return $ readFrom contents reader

readFrom :: BS.ByteString -> StringReader a -> a
readFrom s = fst . flip runState s

isLineBreak :: Char -> Bool
isLineBreak c = c == '\n' || c == '\r'

stripLineBreak :: StringReader ()
stripLineBreak = do
  modify $ BS.dropWhile isLineBreak

getLine :: StringReader BS.ByteString
getLine = do
  s <- get
  let (l, s') = BS.span (not . isLineBreak) s
  put s'
  stripLineBreak
  return l

restLines :: StringReader [BS.ByteString]
restLines = do
  s <- get
  put BS.empty
  return $ BS.lines s

getInt :: Num a => StringReader a
getInt = do
  s <- get
  let l' = BS.dropWhile isSpace s
      (d, ll') = BS.span isDigit l'
  put ll'
  return $ case BS.readInt d of
    Just (i, _) -> fromIntegral i
    Nothing -> error $ "Not an integer: " ++ show d

-- }}}

-- {{{ Suffix Array

newtype SuffixArray = SA { runSA :: UArray Int32 Int32}

data SALcp  = SALcp {
  _sa :: UArray Int32 Int32,
  _sarank :: UArray Int32 Int32,
  -- | salcp[i] = lcp(sa[i], sa[i + 1]) 0 <= i < n - 1
  _salcp :: UArray Int32 Int32
} deriving (Show)

mkSaDoubling :: (Ord a, Eq a) => [a] -> SuffixArray
mkSaDoubling xs = case xs of
  [] -> SA $ array (0, -1) []
  _ -> let extendedSa = runST mk
       in extendedSa & tail & listArray (0, n - 1) & SA
  where
    n = fromIntegral $ length xs :: Int32
    newArr :: ST s (STUArray s Int32 Int32)
    newArr = newArray (0, n) 0

    mk = do
      rank1 <- newArr
      rank2 <- newArr
      radixArr <- newArray (0, n) [] :: ST s (STArray s Int32 [Int32])
      maxr0 <- rerank (return . (initXs!)) initSa rank1
      if maxr0 == n
        then return initSa
        else do
          let c sa' i = do
                idxs <- readArray radixArr i
                writeArray radixArr i []
                return $ List.foldl' (flip (:)) sa' idxs
              radixSort rankFn sa = do
                forM_ sa $ \sidx -> do
                  ridx <- rankFn sidx
                  stack <- readArray radixArr ridx
                  writeArray radixArr ridx (sidx:stack)
                foldM c [] [n, n - 1..0]
              goSa rollingRanks step sa = do
                let (sRank, tRank) = rollingRanks
                    dRankFn d x = let y = x + d
                      in if (y > n) then return 0 else readArray sRank y
                    dRankFn2 i = (,) <$> dRankFn 0 i <*> dRankFn step i
                sa' <- radixSort (dRankFn step) sa
                sa'' <- radixSort (dRankFn 0) sa'
                maxRank <- rerank dRankFn2 sa'' tRank
                if maxRank == n
                  then return sa''
                  else goSa (tRank, sRank) (step + step) sa''
          goSa (rank1, rank2) 1 initSa

    initSa :: [Int32]
    initSa = zip [0..n - 1] xs & List.sortOn snd & map fst & (n:)

    mkArr :: [a] -> Arr.Array Int32 a
    mkArr zs = listArray (0, n - 1) zs
    initXs = mkArr xs

    rerank :: Eq b => (Int32 -> ST s b) -> [Int32] -> (STUArray s Int32 Int32) -> ST s Int32
    rerank valFn inds target = do
      writeArray target headInd 0
      counter <- newSTRef (0 :: Int32)
      forM_ indPairs $ \(pi, i) -> do
        if pi == headInd
          then modifySTRef counter (+1)
          else do
              pv <- valFn pi
              iv <- valFn i
              when (pv /= iv) $ modifySTRef counter (+1)
        c <- readSTRef counter
        writeArray target i c
      readSTRef counter
      where
        headInd = head inds
        indPairs = zip inds (tail inds)

getSaLcp :: (Eq a,  Ord a) => ([a] -> SuffixArray) -> [a] -> SALcp
getSaLcp saFn xs = SALcp sa rank saLcp
  where
    sa = runSA $ saFn xs
    n = (bounds sa & snd) + 1

    rank :: UArray Int32 Int32
    rank = array (0, n - 1) $ map (\(x, y) -> (y, x)) $ assocs sa

    mkArr :: [a] -> Arr.Array Int32 a
    mkArr zs = listArray (0, n - 1) zs
    initXs = mkArr xs

    saLcp = scanl lcp' (-1, 0) [0..n - 1]
      & filter (inRange (0, n - 2) . fst)
      & array (0, n - 2)

    lcp' (r, prevLcp) suffixIdx =
      if thisRk == n - 1 then (n - 1, 0)
      else (thisRk, lcp')
      where
        thisRk = rank ! suffixIdx
        largerSuffixIdx = sa ! (thisRk + 1)
        lcp' = goLcp (max 0 (prevLcp - 1))

        goLcp l = l + (fromIntegral $ length $ takeWhile g [l..])
          where
            g l' =
              let thisEnd = suffixIdx + l'
                  thatEnd = largerSuffixIdx + l'
              in (thisEnd < n) && (thatEnd < n)
                && (initXs ! thisEnd) == (initXs ! thatEnd)

-- }}}

-- {{{ DSU

class Monoid m => Group m where
  groupNegate :: m -> m

-- a is of commutative Monoid
class (Group m, Monoid a) => Ring m a where
  ringMul :: m -> a -> a

instance Group () where
  groupNegate = id
  {-# INLINE groupNegate #-}

instance Group a => Ring a () where
  ringMul _ _ = ()
  {-# INLINE ringMul #-}

data DsuCell i r e =
  DsuRoot {
    componentSize :: Int,
    componentState :: r
  }
  | DsuChild {
    dsuFatherIndex :: i,
    dsuRelation :: e
  }

newtype STDsu s i r e = STDsu {_runDsu :: STArray s i (DsuCell i r e)}

newSTDsu :: Ix i => (i, i) -> [r] -> ST s (STDsu s i r e)
newSTDsu bnds rs = do
  newArr <- newListArray bnds $ map (DsuRoot 1)  rs
  return $ STDsu newArr

readDsuCell :: Ix i => STDsu s i r e -> i -> ST s (DsuCell i r e)
readDsuCell dsu idx = flip readArray idx . _runDsu $ dsu

isRootCell :: DsuCell i r e -> Bool
isRootCell DsuRoot{} = True
isRootCell _ = False

dsuImmeidateRelation :: (Ix i, Monoid e) => i -> STDsu s i r e-> ST s e
dsuImmeidateRelation idx dsuST = do
  cell <- readDsuCell dsuST idx
  case cell of
    DsuChild _ rel -> return rel
    DsuRoot{} -> return mempty

dsuFather :: Ix i => i -> STDsu s i r e -> ST s i
dsuFather idx dsuST = do
  cell <- readDsuCell dsuST idx
  case cell of
    DsuChild f _ -> return f
    DsuRoot{} -> return idx

writeDsuCell :: Ix i => STDsu s i r e -> i -> DsuCell i r e -> ST s ()
writeDsuCell = writeArray . _runDsu

modifyDsuCell :: Ix i => STDsu s i r e -> i -> (DsuCell i r e -> DsuCell i r e) -> ST s ()
modifyDsuCell dsuST i f = do
  cell <- readDsuCell dsuST i
  writeDsuCell dsuST i (f cell)

dsuUpToRootAndCompress :: (Ix i, Monoid e) => i -> STDsu s i r e -> ST s (i, e)
dsuUpToRootAndCompress idx dsuST = do
  fa <- dsuFather idx dsuST
  if fa == idx
    then return (idx, mempty)
    else do
      (rootIdx, faRel) <- dsuUpToRootAndCompress fa dsuST
      thisRel <- dsuImmeidateRelation idx dsuST
      let newRel = thisRel `mappend` faRel
      writeDsuCell dsuST idx (DsuChild rootIdx newRel)
      return (rootIdx, newRel)

dsuUnion :: (Ix i, Ring e r, Group e) => i -> i -> e -> STDsu s i r e -> ST s ()
dsuUnion from to rel dsuST = when (from /= to) $ do
  (fromRoot, fromRel) <- dsuUpToRootAndCompress from dsuST
  (toRoot, toRel) <- dsuUpToRootAndCompress to dsuST
  DsuRoot sFrom _ <- readDsuCell dsuST fromRoot
  DsuRoot sTo _ <- readDsuCell dsuST toRoot
  if sFrom <= sTo
  then connect fromRoot toRoot $
    groupNegate fromRel `mappend` rel `mappend` toRel
  else connect toRoot fromRoot $
    groupNegate toRel `mappend` groupNegate rel `mappend` fromRel
  where
    connect f newRoot newRel = do
      (DsuRoot sf cf) <- readDsuCell dsuST f
      writeDsuCell dsuST f $ DsuChild newRoot newRel
      modifyDsuCell dsuST newRoot $ \(DsuRoot sR cR) ->
        DsuRoot (sR + sf) (ringMul newRel cf `mappend` cR)
-- }}}

instance Ring () (Min Int32) where
  ringMul m a = a

type SolveState = (Int32, [Int])

solve :: [Int] -> [Int]
solve xs = zipWith go prefixes (elems getDupLen) & scanl1 addMod
  where
    modulo = 1000000007

    addMod x y = (x + y) `mod` modulo

    asArr :: Array i e -> Array i e
    asArr = id

    revSaLcp = getSaLcp mkSaDoubling $ reverse xs

    getDupLen =
      let SALcp sa _ salcp = revSaLcp
          n = (+1) . snd $ bounds sa
      in
      runSTUArray $ do
        dupLen <- newArray (0, n - 1) 0 :: ST s (STUArray s Int32 Int32)
        stackRef <- newSTRef []
        let reorderedLcp = assocs sa
              & map (\(rk, sidx) ->
                let l = if rk == n - 1 then 0 else salcp ! rk
                in (sidx, Min l))
              & array (0, n - 1)
              & asArr
              & elems
        dsu <- newSTDsu (0, n - 1) reorderedLcp :: ST s (STDsu s Int32 (Min Int32) ())
        let popAndMerge y [] = return []
            popAndMerge y stack'@(z:_) = do
              dsuUnion y z () dsu
              return stack'
            updateMaxFrom f t = do
              (r, _) <- dsuUpToRootAndCompress f dsu
              Min l' <- (readDsuCell dsu r <&> componentState)
              l <- readArray dupLen (n - 1 - t)
              writeArray dupLen (n - 1 - t) (max l l')
            popCloserToEnd _ [] = return []
            popCloserToEnd x stack'@(y:ys) =
              if (y > x)
                then do
                  updateMaxFrom y x
                  return stack'
                else do
                  updateMaxFrom y y
                  stack'' <- popAndMerge y ys
                  popCloserToEnd x stack''

        forM_ (elems sa) $ \sidx -> do
          stack <- readSTRef stackRef
          stack' <- popCloserToEnd sidx stack
          writeSTRef stackRef (sidx:stack')
        return dupLen

    blacklist :: [Int32]
    blacklist = map (+(bit 4)) [12, 10, 7, 15]

    prefixes = xs & scanl (flip (:)) [] & tail

    lastDigits :: CylLens' Int32 SolveState
    lastDigits = _1

    lastCounts :: CylLens' [Int] SolveState
    lastCounts = _2

    p a x = a .|. (if x >= (bit 4)
        then x & (`clearBit` 4) & (`shiftL` 1) & (`setBit` 4)
        else x `shiftL` 1)

    app1 :: Int -> State SolveState Int
    app1 digit = do
      lastDigits %= (p $ fromIntegral digit)
      (ds, cs) <- get
      let numLastCs = if ds `elem` blacklist then 3 else 4
          newCount = (foldl addMod 0 $ take numLastCs cs)
      lastCounts %= (newCount:) . take 3
      return newCount

    go :: [Int] -> Int32 -> Int
    go prefix dupLen =
      mapM app1 prefix
      & flip runState (1, [1])
      & fst
      & drop (fromIntegral dupLen)
      & List.foldl' addMod 0

main :: IO ()
main = do
  s <- readContents $ do
     m <- getInt
     replicateM m getInt
  solve s & map show & unlines & putStrLn
  return ()

{-# LANGUAGE CPP #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE RankNTypes #-}

import Control.Applicative
import Control.Monad
import Data.Bits
import Data.Char
import Data.Functor
import Data.Maybe
import Data.Monoid hiding ((<>))
import Data.Semigroup

import qualified Data.ByteString.Lazy.Char8 as BS

#if __GLASGOW_HASKELL__ >= 713
import Control.Monad.Trans.State
import Control.Monad.Trans.Reader
import Data.Functor.Identity
#endif

import Control.Monad.ST.Safe
import Data.Function
import Data.Array.IArray
import Data.Array.MArray.Safe
import Data.Array.ST.Safe
import Data.Array.Unboxed
import Data.Int
import Data.STRef
import qualified Data.List as List
import qualified Data.Array as Arr

-- {{{ Functors

#if __GLASGOW_HASKELL__ < 713
newtype Identity a = Identity {runIdentity :: a}

instance Functor Identity where
  fmap f (Identity x) = Identity $ f x
#endif

-- }}}

-- {{{ Monads

#if __GLASGOW_HASKELL__ < 713
newtype Reader a b = Reader {runReader :: a -> b}
newtype State s a = State {runState :: s -> (a, s)}

instance Functor (Reader a) where
  fmap f =  Reader . (f . ). runReader
  {-# INLINE fmap #-}

instance Applicative (Reader a) where
  pure = Reader . const
  {-# INLINE pure #-}
  a <*> b = Reader f'
    where
      f1 = runReader a
      f2 = runReader b
      f' = \p -> (f1 p) (f2 p)
  {-# INLINE (<*>) #-}

instance Monad (Reader a) where
  r1 >>= r2 = Reader $ \a -> runReader (r2 $ runReader r1 a) a
  {-# INLINE (>>=) #-}
  return = pure

ask :: Reader a a
ask = Reader id
{-# INLINE ask #-}
local :: (a -> a) -> Reader a b -> Reader a b
local f r = let f' = (runReader r) . f in Reader f'
{-# INLINE local #-}

instance Functor (State s) where
  fmap f st = State $ \s -> let (a, s') = runState st s in (f a, s')

instance Applicative (State s) where
  pure = State . (,)
  {-# INLINE pure #-}
  s1 <*> s2 = State $ \s ->
    let (f, s') = runState s1 s
        (a, s'') = runState s2 s'
    in (f a, s'')

instance Monad (State s) where
  s1 >>= ms2 = State $ \s ->
    let (a, s') = runState s1 s
    in runState (ms2 a) s'
  return = pure

put :: s -> State s ()
put = State . const . ((,) ())
{-# INLINE put #-}
get :: State s s
get = State $ \s -> (s, s)
{-# INLINE get #-}
execState :: State s a -> s -> s
execState st s0 = snd $ runState st s0
#endif

-- }}}

-- {{{ Lens

type CylLens a s b t = forall f. Functor f => (a -> f s) -> b -> f t
type CylLens' a b = CylLens a a b b
lens :: (b -> a) -> (b -> s -> t) -> CylLens a s b t
lens r w g b = w b <$> g (r b)
{-# INLINE lens #-}
iso :: (a -> b) -> (b -> a) -> CylLens' a b
iso f f' = let f'' _ a = f a in lens f' f''
{-# INLINE iso #-}
lensGet :: CylLens a s b t -> b -> a
lensGet lens = getConst . lens Const
{-# INLINE lensGet #-}
lensSet :: CylLens a s b t -> b -> s -> t
lensSet lens b s = runIdentity $ lens (Identity . const s) b
{-# INLINE lensSet #-}

#if __GLASGOW_HASKELL__ < 713
infix 1 &
#endif

infix 8 ^.
infix 4 .=, %=
infixr 4 .~, %~

#if __GLASGOW_HASKELL__ < 713
(&) :: a -> (a -> b) -> b
a & f = f a
{-# INLINE (&) #-}
#endif

(^.) :: b -> CylLens a s b t -> a
b ^. lens = lensGet lens b
{-# INLINE (^.) #-}
(%~) :: CylLens a s b t -> (a -> s) -> (b -> t)
(lens %~ f) b = lensSet lens b (f $ lensGet lens b)
{-# INLINE (%~) #-}
(.~) :: CylLens a s b t -> s -> (b -> t)
(lens .~ v) b = lensSet lens b v
{-# INLINE (.~) #-}
(.=) :: CylLens a a' s s -> a' -> State s ()
lens .= v = do {s <- get; put $ s & lens .~ v}
{-# INLINE (.=) #-}
(%=) :: CylLens a a' s s -> (a -> a') -> State s ()
lens %= f = do {s <- get; put $ s & lens %~ f}
{-# INLINE (%=) #-}
view :: CylLens a a' s s' -> Reader s a
view l = ask >>= return . (^. l)
use :: CylLens a a' s s' -> State s a
use l = get >>= return . (^. l)
zoom :: CylLens' s' s -> State s' c -> State s c
zoom l m = do
  s' <- use l
  let (c, s'') = runState m s'
  l .= s''
  return c

-- }}}

-- {{{ Common used lens

class Has1 m a | m -> a where
  _1 :: CylLens' a m

class Has2 m a | m -> a where
  _2 :: CylLens' a m

class Has3 m a | m -> a where
  _3 :: CylLens' a m

class Has4 m a | m -> a where
  _4 :: CylLens' a m

class Has5 m a | m -> a where
  _5 :: CylLens' a m

class Has6 m a | m -> a where
  _6 :: CylLens' a m

instance Has1 ((,) a b) a where
  _1 = lens fst $ \(a, b) c -> (c, b)
  {-# INLINE _1 #-}

instance Has1 ((,,) a b c) a where
  _1 = lens (\(a, _, _) -> a) $ \(a, b, c) d -> (d, b, c)
  {-# INLINE _1 #-}

instance Has1 ((,,,) a b c d) a where
  _1 = lens (\(a, _, _, _) -> a) $ \(a, b, c, d) e -> (e, b, c, d)
  {-# INLINE _1 #-}

instance Has1 ((,,,,) a b c d e) a where
  _1 = lens (\(a, _, _, _, _) -> a) $ \(a, b, c, d, e) f -> (f, b, c, d, e)
  {-# INLINE _1 #-}

instance Has1 ((,,,,,) a b c d e f) a where
  _1 = lens (\(a, _, _, _, _, _) -> a) $ \(a, b, c, d, e, f) g -> (g, b, c, d, e, f)
  {-# INLINE _1 #-}

instance Has2 ((,) a b) b where
  _2 = lens snd $ \(a, b) c -> (a, c)
  {-# INLINE _2 #-}

instance Has2 ((,,) a b c) b where
  _2 = lens (\(_, b, _) -> b) $ \(a, b, c) d -> (a, d, c)
  {-# INLINE _2 #-}

instance Has2 ((,,,) a b c d) b where
  _2 = lens (\(_, b, _, _) -> b) $ \(a, b, c, d) e -> (a, e, c, d)
  {-# INLINE _2 #-}

instance Has2 ((,,,,) a b c d e) b where
  _2 = lens (\(_, b, _, _, _) -> b) $ \(a, b, c, d, e) f -> (a, f, c, d, e)
  {-# INLINE _2 #-}

instance Has2 ((,,,,,) a b c d e f) b where
  _2 = lens (\(_, b, _, _, _, _) -> b) $ \(a, b, c, d, e, f) g -> (a, g, c, d, e, f)
  {-# INLINE _2 #-}

instance Has3 ((,,) a b c) c where
  _3 = lens (\(_, _, c) -> c) $ \(a, b, c) d -> (a, b, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,) a b c d) c where
  _3 = lens (\(_, _, c, _) -> c) $ \(a, b, c, d) e -> (a, b, e, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,,) a b c d e) c where
  _3 = lens (\(_, _, c, _, _) -> c) $ \(a, b, c, d, e) f -> (a, b, f, d, e)
  {-# INLINE _3 #-}

instance Has3 ((,,,,,) a b c d e f) c where
  _3 = lens (\(_, _, c, _, _, _) -> c) $ \(a, b, c, d, e, f) g -> (a, b, g, d, e, f)
  {-# INLINE _3 #-}

instance Has4 ((,,,) a b c d) d where
  _4 = lens (\(_, _, _, d) -> d) $ \(a, b, c, d) e -> (a, b, c, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,) a b c d e) d where
  _4 = lens (\(_, _, _, d, _) -> d) $ \(a, b, c, d, e) f -> (a, b, c, f, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,,) a b c d e f) d where
  _4 = lens (\(_, _, _, d, _, _) -> d) $ \(a, b, c, d, e, f) g -> (a, b, c, g, e, f)
  {-# INLINE _4 #-}

instance Has5 ((,,,,) a b c d e) e where
  _5 = lens (\(_, _, _, _, e) -> e) $ \(a, b, c, d, e) f -> (a, b, c, d, f)
  {-# INLINE _5 #-}

instance Has5 ((,,,,,) a b c d e f) e where
  _5 = lens (\(_, _, _, _, e, _) -> e) $ \(a, b, c, d, e, f) g -> (a, b, c, d, g, f)
  {-# INLINE _5 #-}

instance Has6 ((,,,,,) a b c d e f) f where
  _6 = lens (\(_, _, _, _, _, f) -> f) $ \(a, b, c, d, e, f) g -> (a, b, c, d, e, g)
  {-# INLINE _6 #-}

-- }}}

-- {{{ Handy IO

type StringReader a = State BS.ByteString a

readContents :: StringReader a -> IO a
readContents reader = do
  contents <- BS.getContents
  return $ readFrom contents reader

readFrom :: BS.ByteString -> StringReader a -> a
readFrom s = fst . flip runState s

isLineBreak :: Char -> Bool
isLineBreak c = c == '\n' || c == '\r'

stripLineBreak :: StringReader ()
stripLineBreak = do
  modify $ BS.dropWhile isLineBreak

getLine :: StringReader BS.ByteString
getLine = do
  s <- get
  let (l, s') = BS.span (not . isLineBreak) s
  put s'
  stripLineBreak
  return l

restLines :: StringReader [BS.ByteString]
restLines = do
  s <- get
  put BS.empty
  return $ BS.lines s

getInt :: Num a => StringReader a
getInt = do
  s <- get
  let l' = BS.dropWhile isSpace s
      (d, ll') = BS.span isDigit l'
  put ll'
  return $ case BS.readInt d of
    Just (i, _) -> fromIntegral i
    Nothing -> error $ "Not an integer: " ++ show d

-- }}}

-- {{{ Suffix Array

newtype SuffixArray = SA { runSA :: UArray Int32 Int32}

data SALcp  = SALcp {
  _sa :: UArray Int32 Int32,
  _sarank :: UArray Int32 Int32,
  -- | salcp[i] = lcp(sa[i], sa[i + 1]) 0 <= i < n - 1
  _salcp :: UArray Int32 Int32
} deriving (Show)

mkSaDoubling :: (Ord a, Eq a) => [a] -> SuffixArray
mkSaDoubling xs = case xs of
  [] -> SA $ array (0, -1) []
  _ -> let extendedSa = runST mk
       in extendedSa & tail & listArray (0, n - 1) & SA
  where
    n = fromIntegral $ length xs :: Int32
    newArr :: ST s (STUArray s Int32 Int32)
    newArr = newArray (0, n) 0

    mk = do
      rank1 <- newArr
      rank2 <- newArr
      radixArr <- newArray (0, n) [] :: ST s (STArray s Int32 [Int32])
      maxr0 <- rerank (return . (initXs!)) initSa rank1
      if maxr0 == n
        then return initSa
        else do
          let c sa' i = do
                idxs <- readArray radixArr i
                writeArray radixArr i []
                return $ List.foldl' (flip (:)) sa' idxs
              radixSort rankFn sa = do
                forM_ sa $ \sidx -> do
                  ridx <- rankFn sidx
                  stack <- readArray radixArr ridx
                  writeArray radixArr ridx (sidx:stack)
                foldM c [] [n, n - 1..0]
              goSa rollingRanks step sa = do
                let (sRank, tRank) = rollingRanks
                    dRankFn d x = let y = x + d
                      in if (y > n) then return 0 else readArray sRank y
                    dRankFn2 i = (,) <$> dRankFn 0 i <*> dRankFn step i
                sa' <- radixSort (dRankFn step) sa
                sa'' <- radixSort (dRankFn 0) sa'
                maxRank <- rerank dRankFn2 sa'' tRank
                if maxRank == n
                  then return sa''
                  else goSa (tRank, sRank) (step + step) sa''
          goSa (rank1, rank2) 1 initSa

    initSa :: [Int32]
    initSa = zip [0..n - 1] xs & List.sortOn snd & map fst & (n:)

    mkArr :: [a] -> Arr.Array Int32 a
    mkArr zs = listArray (0, n - 1) zs
    initXs = mkArr xs

    rerank :: Eq b => (Int32 -> ST s b) -> [Int32] -> (STUArray s Int32 Int32) -> ST s Int32
    rerank valFn inds target = do
      writeArray target headInd 0
      counter <- newSTRef (0 :: Int32)
      forM_ indPairs $ \(pi, i) -> do
        if pi == headInd
          then modifySTRef counter (+1)
          else do
              pv <- valFn pi
              iv <- valFn i
              when (pv /= iv) $ modifySTRef counter (+1)
        c <- readSTRef counter
        writeArray target i c
      readSTRef counter
      where
        headInd = head inds
        indPairs = zip inds (tail inds)

getSaLcp :: (Eq a,  Ord a) => ([a] -> SuffixArray) -> [a] -> SALcp
getSaLcp saFn xs = SALcp sa rank saLcp
  where
    sa = runSA $ saFn xs
    n = (bounds sa & snd) + 1

    rank :: UArray Int32 Int32
    rank = array (0, n - 1) $ map (\(x, y) -> (y, x)) $ assocs sa

    mkArr :: [a] -> Arr.Array Int32 a
    mkArr zs = listArray (0, n - 1) zs
    initXs = mkArr xs

    saLcp = scanl lcp' (-1, 0) [0..n - 1]
      & filter (inRange (0, n - 2) . fst)
      & array (0, n - 2)

    lcp' (r, prevLcp) suffixIdx =
      if thisRk == n - 1 then (n - 1, 0)
      else (thisRk, lcp')
      where
        thisRk = rank ! suffixIdx
        largerSuffixIdx = sa ! (thisRk + 1)
        lcp' = goLcp (max 0 (prevLcp - 1))

        goLcp l = l + (fromIntegral $ length $ takeWhile g [l..])
          where
            g l' =
              let thisEnd = suffixIdx + l'
                  thatEnd = largerSuffixIdx + l'
              in (thisEnd < n) && (thatEnd < n)
                && (initXs ! thisEnd) == (initXs ! thatEnd)

-- }}}

-- {{{ DSU

class Monoid m => Group m where
  groupNegate :: m -> m

-- a is of commutative Monoid
class (Group m, Monoid a) => Ring m a where
  ringMul :: m -> a -> a

instance Group () where
  groupNegate = id
  {-# INLINE groupNegate #-}

instance Group a => Ring a () where
  ringMul _ _ = ()
  {-# INLINE ringMul #-}

data DsuCell i r e =
  DsuRoot {
    componentSize :: Int,
    componentState :: r
  }
  | DsuChild {
    dsuFatherIndex :: i,
    dsuRelation :: e
  }

newtype STDsu s i r e = STDsu {_runDsu :: STArray s i (DsuCell i r e)}

newSTDsu :: Ix i => (i, i) -> [r] -> ST s (STDsu s i r e)
newSTDsu bnds rs = do
  newArr <- newListArray bnds $ map (DsuRoot 1)  rs
  return $ STDsu newArr

readDsuCell :: Ix i => STDsu s i r e -> i -> ST s (DsuCell i r e)
readDsuCell dsu idx = flip readArray idx . _runDsu $ dsu

isRootCell :: DsuCell i r e -> Bool
isRootCell DsuRoot{} = True
isRootCell _ = False

dsuImmeidateRelation :: (Ix i, Monoid e) => i -> STDsu s i r e-> ST s e
dsuImmeidateRelation idx dsuST = do
  cell <- readDsuCell dsuST idx
  case cell of
    DsuChild _ rel -> return rel
    DsuRoot{} -> return mempty

dsuFather :: Ix i => i -> STDsu s i r e -> ST s i
dsuFather idx dsuST = do
  cell <- readDsuCell dsuST idx
  case cell of
    DsuChild f _ -> return f
    DsuRoot{} -> return idx

writeDsuCell :: Ix i => STDsu s i r e -> i -> DsuCell i r e -> ST s ()
writeDsuCell = writeArray . _runDsu

modifyDsuCell :: Ix i => STDsu s i r e -> i -> (DsuCell i r e -> DsuCell i r e) -> ST s ()
modifyDsuCell dsuST i f = do
  cell <- readDsuCell dsuST i
  writeDsuCell dsuST i (f cell)

dsuUpToRootAndCompress :: (Ix i, Monoid e) => i -> STDsu s i r e -> ST s (i, e)
dsuUpToRootAndCompress idx dsuST = do
  fa <- dsuFather idx dsuST
  if fa == idx
    then return (idx, mempty)
    else do
      (rootIdx, faRel) <- dsuUpToRootAndCompress fa dsuST
      thisRel <- dsuImmeidateRelation idx dsuST
      let newRel = thisRel `mappend` faRel
      writeDsuCell dsuST idx (DsuChild rootIdx newRel)
      return (rootIdx, newRel)

dsuUnion :: (Ix i, Ring e r, Group e) => i -> i -> e -> STDsu s i r e -> ST s ()
dsuUnion from to rel dsuST = when (from /= to) $ do
  (fromRoot, fromRel) <- dsuUpToRootAndCompress from dsuST
  (toRoot, toRel) <- dsuUpToRootAndCompress to dsuST
  DsuRoot sFrom _ <- readDsuCell dsuST fromRoot
  DsuRoot sTo _ <- readDsuCell dsuST toRoot
  if sFrom <= sTo
  then connect fromRoot toRoot $
    groupNegate fromRel `mappend` rel `mappend` toRel
  else connect toRoot fromRoot $
    groupNegate toRel `mappend` groupNegate rel `mappend` fromRel
  where
    connect f newRoot newRel = do
      (DsuRoot sf cf) <- readDsuCell dsuST f
      writeDsuCell dsuST f $ DsuChild newRoot newRel
      modifyDsuCell dsuST newRoot $ \(DsuRoot sR cR) ->
        DsuRoot (sR + sf) (ringMul newRel cf `mappend` cR)
-- }}}

instance Ring () (Min Int32) where
  ringMul m a = a

type SolveState = (Int32, [Int])

data PrefixSolveState = PSS {
  _total :: Int
}

solve :: [Int] -> [Int]
solve xs = zipWith go prefixes (elems getDupLen) & scanl1 addMod
  where
    modulo = 1000000007

    addMod x y = (x + y) `mod` modulo

    asArr :: Array i e -> Array i e
    asArr = id

    revSaLcp = getSaLcp mkSaDoubling $ reverse xs

    getDupLen =
      let SALcp sa _ salcp = revSaLcp
          n = (+1) . snd $ bounds sa
      in
      runSTUArray $ do
        dupLen <- newArray (0, n - 1) 0 :: ST s (STUArray s Int32 Int32)
        stackRef <- newSTRef []
        let reorderedLcp = assocs sa
              & map (\(rk, sidx) ->
                let l = if rk == n - 1 then 0 else salcp ! rk
                in (sidx, Min l))
              & array (0, n - 1)
              & asArr
              & elems
        dsu <- newSTDsu (0, n - 1) reorderedLcp :: ST s (STDsu s Int32 (Min Int32) ())
        let popAndMerge y [] = return []
            popAndMerge y stack'@(z:_) = do
              dsuUnion y z () dsu
              return stack'
            updateMaxFrom f t = do
              (r, _) <- dsuUpToRootAndCompress f dsu
              Min l' <- (readDsuCell dsu r <&> componentState)
              l <- readArray dupLen (n - 1 - t)
              writeArray dupLen (n - 1 - t) (max l l')
            popCloserToEnd _ [] = return []
            popCloserToEnd x stack'@(y:ys) =
              if (y > x)
                then do
                  updateMaxFrom y x
                  return stack'
                else do
                  updateMaxFrom y y
                  stack'' <- popAndMerge y ys
                  popCloserToEnd x stack''

        forM_ (elems sa) $ \sidx -> do
          stack <- readSTRef stackRef
          stack' <- popCloserToEnd sidx stack
          writeSTRef stackRef (sidx:stack')
        return dupLen

    -- blacklist = map (map (\c -> (ord c) - (ord '0')))
    --   ["0011", "0101", "1110", "1111"]
    blacklist :: [Int32]
    blacklist = map (+(bit 4)) [12, 10, 7, 15]

    prefixes = xs & scanl (flip (:)) [] & tail

    lastDigits :: CylLens' Int32 SolveState
    lastDigits = _1

    lastCounts :: CylLens' [Int] SolveState
    lastCounts = _2

    p a x = a .|. (if x >= (bit 4)
        then x & (`clearBit` 4) & (`shiftL` 1) & (`setBit` 4)
        else x `shiftL` 1)

    app1 :: Int -> State SolveState Int
    app1 digit = do
      lastDigits %= (p $ fromIntegral digit)
      (ds, cs) <- get
      let numLastCs = if ds `elem` blacklist then 3 else 4
          newCount = (foldl addMod 0 $ take numLastCs cs)
      lastCounts %= (newCount:) . take 3
      return newCount

    go :: [Int] -> Int32 -> Int
    go prefix dupLen =
      mapM app1 prefix
      & flip runState (1, [1])
      & fst
      & drop (fromIntegral dupLen)
      & List.foldl' addMod 0

main :: IO ()
main = do
  s <- readContents $ do
     m <- getInt
     replicateM m getInt
  solve s & map show & unlines & putStrLn
  return ()

{-# LANGUAGE CPP #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}

import Control.Applicative
import Control.Monad
import Data.Char
import Data.Function
import Data.Functor

import qualified Data.Map.Strict as Map
import qualified Data.ByteString.Lazy.Char8 as BS

#if __GLASGOW_HASKELL__ >= 713
import Control.Monad.Trans.State
import Control.Monad.Trans.Reader
import Data.Functor.Identity
#endif

-- {{{ Functors

#if __GLASGOW_HASKELL__ < 713
newtype Identity a = Identity {runIdentity :: a}

instance Functor Identity where
  fmap f (Identity x) = Identity $ f x
#endif

-- }}}

-- {{{ Monads

#if __GLASGOW_HASKELL__ < 713
newtype Reader a b = Reader {runReader :: a -> b}
newtype State s a = State {runState :: s -> (a, s)}

instance Functor (Reader a) where
  fmap f =  Reader . (f . ). runReader
  {-# INLINE fmap #-}

instance Applicative (Reader a) where
  pure = Reader . const
  {-# INLINE pure #-}
  a <*> b = Reader f'
    where
      f1 = runReader a
      f2 = runReader b
      f' = \p -> (f1 p) (f2 p)
  {-# INLINE (<*>) #-}

instance Monad (Reader a) where
  r1 >>= r2 = Reader $ \a -> runReader (r2 $ runReader r1 a) a
  {-# INLINE (>>=) #-}
  return = pure

ask :: Reader a a
ask = Reader id
{-# INLINE ask #-}
local :: (a -> a) -> Reader a b -> Reader a b
local f r = let f' = (runReader r) . f in Reader f'
{-# INLINE local #-}

instance Functor (State s) where
  fmap f st = State $ \s -> let (a, s') = runState st s in (f a, s')

instance Applicative (State s) where
  pure = State . (,)
  {-# INLINE pure #-}
  s1 <*> s2 = State $ \s ->
    let (f, s') = runState s1 s
        (a, s'') = runState s2 s'
    in (f a, s'')

instance Monad (State s) where
  s1 >>= ms2 = State $ \s ->
    let (a, s') = runState s1 s
    in runState (ms2 a) s'
  return = pure

put :: s -> State s ()
put = State . const . ((,) ())
{-# INLINE put #-}
get :: State s s
get = State $ \s -> (s, s)
{-# INLINE get #-}
execState :: State s a -> s -> s
execState st s0 = snd $ runState st s0
#endif

-- }}}

-- {{{ Lens

type CylLens a s b t = forall f. Functor f => (a -> f s) -> b -> f t
type CylLens' a b = CylLens a a b b
lens :: (b -> a) -> (b -> s -> t) -> CylLens a s b t
lens r w g b = w b <$> g (r b)
{-# INLINE lens #-}
iso :: (a -> b) -> (b -> a) -> CylLens' a b
iso f f' = let f'' _ a = f a in lens f' f''
{-# INLINE iso #-}
lensGet :: CylLens a s b t -> b -> a
lensGet lens = getConst . lens Const
{-# INLINE lensGet #-}
lensSet :: CylLens a s b t -> b -> s -> t
lensSet lens b s = runIdentity $ lens (Identity . const s) b
{-# INLINE lensSet #-}

#if __GLASGOW_HASKELL__ < 713
infix 1 &
#endif

infix 8 ^.
infix 4 .=, %=
infixr 4 .~, %~

#if __GLASGOW_HASKELL__ < 713
(&) :: a -> (a -> b) -> b
a & f = f a
{-# INLINE (&) #-}
#endif

(^.) :: b -> CylLens a s b t -> a
b ^. lens = lensGet lens b
{-# INLINE (^.) #-}
(%~) :: CylLens a s b t -> (a -> s) -> (b -> t)
(lens %~ f) b = lensSet lens b (f $ lensGet lens b)
{-# INLINE (%~) #-}
(.~) :: CylLens a s b t -> s -> (b -> t)
(lens .~ v) b = lensSet lens b v
{-# INLINE (.~) #-}
(.=) :: CylLens a a' s s -> a' -> State s ()
lens .= v = do {s <- get; put $ s & lens .~ v}
{-# INLINE (.=) #-}
(%=) :: CylLens a a' s s -> (a -> a') -> State s ()
lens %= f = do {s <- get; put $ s & lens %~ f}
{-# INLINE (%=) #-}
view :: CylLens a a' s s' -> Reader s a
view l = ask >>= return . (^. l)
use :: CylLens a a' s s' -> State s a
use l = get >>= return . (^. l)
zoom :: CylLens' s' s -> State s' c -> State s c
zoom l m = do
  s' <- use l
  let (c, s'') = runState m s'
  l .= s''
  return c

-- }}}

-- {{{ Common used lens

class Has1 m a | m -> a where
  _1 :: CylLens' a m

class Has2 m a | m -> a where
  _2 :: CylLens' a m

class Has3 m a | m -> a where
  _3 :: CylLens' a m

class Has4 m a | m -> a where
  _4 :: CylLens' a m

class Has5 m a | m -> a where
  _5 :: CylLens' a m

class Has6 m a | m -> a where
  _6 :: CylLens' a m

instance Has1 ((,) a b) a where
  _1 = lens fst $ \(a, b) c -> (c, b)
  {-# INLINE _1 #-}

instance Has1 ((,,) a b c) a where
  _1 = lens (\(a, _, _) -> a) $ \(a, b, c) d -> (d, b, c)
  {-# INLINE _1 #-}

instance Has1 ((,,,) a b c d) a where
  _1 = lens (\(a, _, _, _) -> a) $ \(a, b, c, d) e -> (e, b, c, d)
  {-# INLINE _1 #-}

instance Has1 ((,,,,) a b c d e) a where
  _1 = lens (\(a, _, _, _, _) -> a) $ \(a, b, c, d, e) f -> (f, b, c, d, e)
  {-# INLINE _1 #-}

instance Has1 ((,,,,,) a b c d e f) a where
  _1 = lens (\(a, _, _, _, _, _) -> a) $ \(a, b, c, d, e, f) g -> (g, b, c, d, e, f)
  {-# INLINE _1 #-}

instance Has2 ((,) a b) b where
  _2 = lens snd $ \(a, b) c -> (a, c)
  {-# INLINE _2 #-}

instance Has2 ((,,) a b c) b where
  _2 = lens (\(_, b, _) -> b) $ \(a, b, c) d -> (a, d, c)
  {-# INLINE _2 #-}

instance Has2 ((,,,) a b c d) b where
  _2 = lens (\(_, b, _, _) -> b) $ \(a, b, c, d) e -> (a, e, c, d)
  {-# INLINE _2 #-}

instance Has2 ((,,,,) a b c d e) b where
  _2 = lens (\(_, b, _, _, _) -> b) $ \(a, b, c, d, e) f -> (a, f, c, d, e)
  {-# INLINE _2 #-}

instance Has2 ((,,,,,) a b c d e f) b where
  _2 = lens (\(_, b, _, _, _, _) -> b) $ \(a, b, c, d, e, f) g -> (a, g, c, d, e, f)
  {-# INLINE _2 #-}

instance Has3 ((,,) a b c) c where
  _3 = lens (\(_, _, c) -> c) $ \(a, b, c) d -> (a, b, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,) a b c d) c where
  _3 = lens (\(_, _, c, _) -> c) $ \(a, b, c, d) e -> (a, b, e, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,,) a b c d e) c where
  _3 = lens (\(_, _, c, _, _) -> c) $ \(a, b, c, d, e) f -> (a, b, f, d, e)
  {-# INLINE _3 #-}

instance Has3 ((,,,,,) a b c d e f) c where
  _3 = lens (\(_, _, c, _, _, _) -> c) $ \(a, b, c, d, e, f) g -> (a, b, g, d, e, f)
  {-# INLINE _3 #-}

instance Has4 ((,,,) a b c d) d where
  _4 = lens (\(_, _, _, d) -> d) $ \(a, b, c, d) e -> (a, b, c, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,) a b c d e) d where
  _4 = lens (\(_, _, _, d, _) -> d) $ \(a, b, c, d, e) f -> (a, b, c, f, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,,) a b c d e f) d where
  _4 = lens (\(_, _, _, d, _, _) -> d) $ \(a, b, c, d, e, f) g -> (a, b, c, g, e, f)
  {-# INLINE _4 #-}

instance Has5 ((,,,,) a b c d e) e where
  _5 = lens (\(_, _, _, _, e) -> e) $ \(a, b, c, d, e) f -> (a, b, c, d, f)
  {-# INLINE _5 #-}

instance Has5 ((,,,,,) a b c d e f) e where
  _5 = lens (\(_, _, _, _, e, _) -> e) $ \(a, b, c, d, e, f) g -> (a, b, c, d, g, f)
  {-# INLINE _5 #-}

instance Has6 ((,,,,,) a b c d e f) f where
  _6 = lens (\(_, _, _, _, _, f) -> f) $ \(a, b, c, d, e, f) g -> (a, b, c, d, e, g)
  {-# INLINE _6 #-}

-- }}}

-- {{{ Handy IO

type StringReader a = State BS.ByteString a

readContents :: StringReader a -> IO a
readContents reader = do
  contents <- BS.getContents
  return $ readFrom contents reader

readFrom :: BS.ByteString -> StringReader a -> a
readFrom s = fst . flip runState s

isLineBreak :: Char -> Bool
isLineBreak c = c == '\n' || c == '\r'

stripLineBreak :: StringReader ()
stripLineBreak = do
  modify $ BS.dropWhile isLineBreak

getLine :: StringReader BS.ByteString
getLine = do
  s <- get
  let (l, s') = BS.span (not . isLineBreak) s
  put s'
  stripLineBreak
  return l

restLines :: StringReader [BS.ByteString]
restLines = do
  s <- get
  put BS.empty
  return $ BS.lines s

getInt :: Num a => StringReader a
getInt = do
  s <- get
  let l' = BS.dropWhile isSpace s
      (d, ll') = BS.span isDigit l'
  put ll'
  return $ case BS.readInt d of
    Just (i, _) -> fromIntegral i
    Nothing -> error $ "Not an integer: " ++ show d

-- }}}

type SolveState = ([Int], [Int])
type SolveStateMap = Map.Map Int SolveState

data PrefixSolveState = PSS {
  _ssm :: SolveStateMap,
  _total :: Int
}
_pssIso :: CylLens' (SolveStateMap, Int) PrefixSolveState
_pssIso = iso (uncurry PSS) (\(PSS a b) -> (a, b))
ssm :: CylLens' SolveStateMap PrefixSolveState
ssm = _pssIso . _1
total :: CylLens' Int PrefixSolveState
total = _pssIso . _2

solve :: [Int] -> [Int]
solve xs = scanl1 addMod $ fst $ runState resultM (Map.singleton 0 ([], [1]))
  where
    modulo = 1000000007
    factor = 7919

    addMod x y = (x + y) `mod` modulo

    blacklist = map (map (\c -> (ord c) - (ord '0')))
      ["0011", "0101", "1110", "1111"]

    prefixes = xs & scanl (flip (:)) [] & drop 1
    resultM = forM prefixes app

    lastDigits :: CylLens' [Int] SolveState
    lastDigits = _1

    lastCounts :: CylLens' [Int] SolveState
    lastCounts = _2

    p a = (a:) . take 3

    app1 :: Int -> State SolveState ()
    app1 digit = do
      lastDigits %= (p digit)
      (ds, cs) <- get
      let numLastCs = if ds `elem` blacklist then 3 else 4
          newCount = (foldl addMod 0 $ take numLastCs cs)
      lastCounts %= (p newCount)
      return ()

    hashSeq :: [Int] -> [Int]
    hashSeq = drop 1 . scanl (\ph x -> (ph * factor + x + 1) `mod` modulo) 0

    app :: [Int] -> State SolveStateMap Int
    app prefix = prefixResult
      where
        hs = hashSeq prefix

        getPhs :: SolveStateMap -> [(Int, Int, Int)]
        getPhs ssm = prefix
          & zip hs
          & zipWith (\prevH (h, p) -> (prevH, h, p)) (0:hs)

        app' :: (Int, Int, Int) -> State PrefixSolveState ()
        app' (prevH, h, c) = do
          stateMap <- use ssm
          let prevS = stateMap Map.! prevH
              newS = execState (app1 c) prevS
          ssm %= Map.insert h newS
          let cnt = newS ^. lastCounts & head
          total %=  (addMod cnt)

        prefixResult :: State SolveStateMap Int
        prefixResult = do
          stateMap <- get
          let phs = getPhs stateMap
                & filter (not . (`Map.member` stateMap) . (^. _2))
              m = forM_ phs app'
              pss = execState m (PSS stateMap 0)
          put (pss ^. ssm)
          return (pss ^. total)

main :: IO ()
main = do
  s <- readContents $ do
     m <- getInt
     replicateM m getInt
  solve s & map show & unlines & putStrLn
  return ()

{-# LANGUAGE CPP #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}

import Control.Applicative
import Control.Monad
import Data.Char
import Data.Function
import Data.Functor

import qualified Data.Map.Strict as Map
import qualified Data.ByteString.Lazy.Char8 as BS

#if __GLASGOW_HASKELL__ >= 713
import Control.Monad.Trans.State
import Control.Monad.Trans.Reader
import Data.Functor.Identity
#endif

-- {{{ Functors

#if __GLASGOW_HASKELL__ < 713
newtype Identity a = Identity {runIdentity :: a}

instance Functor Identity where
  fmap f (Identity x) = Identity $ f x
#endif

-- }}}

-- {{{ Monads

#if __GLASGOW_HASKELL__ < 713
newtype Reader a b = Reader {runReader :: a -> b}
newtype State s a = State {runState :: s -> (a, s)}

instance Functor (Reader a) where
  fmap f =  Reader . (f . ). runReader
  {-# INLINE fmap #-}

instance Applicative (Reader a) where
  pure = Reader . const
  {-# INLINE pure #-}
  a <*> b = Reader f'
    where
      f1 = runReader a
      f2 = runReader b
      f' = \p -> (f1 p) (f2 p)
  {-# INLINE (<*>) #-}

instance Monad (Reader a) where
  r1 >>= r2 = Reader $ \a -> runReader (r2 $ runReader r1 a) a
  {-# INLINE (>>=) #-}
  return = pure

ask :: Reader a a
ask = Reader id
{-# INLINE ask #-}
local :: (a -> a) -> Reader a b -> Reader a b
local f r = let f' = (runReader r) . f in Reader f'
{-# INLINE local #-}

instance Functor (State s) where
  fmap f st = State $ \s -> let (a, s') = runState st s in (f a, s')

instance Applicative (State s) where
  pure = State . (,)
  {-# INLINE pure #-}
  s1 <*> s2 = State $ \s ->
    let (f, s') = runState s1 s
        (a, s'') = runState s2 s'
    in (f a, s'')

instance Monad (State s) where
  s1 >>= ms2 = State $ \s ->
    let (a, s') = runState s1 s
    in runState (ms2 a) s'
  return = pure

put :: s -> State s ()
put = State . const . ((,) ())
{-# INLINE put #-}
get :: State s s
get = State $ \s -> (s, s)
{-# INLINE get #-}
execState :: State s a -> s -> s
execState st s0 = snd $ runState st s0
#endif

-- }}}

-- {{{ Lens

type CylLens a s b t = forall f. Functor f => (a -> f s) -> b -> f t
type CylLens' a b = CylLens a a b b
lens :: (b -> a) -> (b -> s -> t) -> CylLens a s b t
lens r w g b = w b <$> g (r b)
{-# INLINE lens #-}
iso :: (a -> b) -> (b -> a) -> CylLens' a b
iso f f' = let f'' _ a = f a in lens f' f''
{-# INLINE iso #-}
lensGet :: CylLens a s b t -> b -> a
lensGet lens = getConst . lens Const
{-# INLINE lensGet #-}
lensSet :: CylLens a s b t -> b -> s -> t
lensSet lens b s = runIdentity $ lens (Identity . const s) b
{-# INLINE lensSet #-}

#if __GLASGOW_HASKELL__ < 713
infix 1 &
#endif

infix 8 ^.
infix 4 .=, %=
infixr 4 .~, %~

#if __GLASGOW_HASKELL__ < 713
(&) :: a -> (a -> b) -> b
a & f = f a
{-# INLINE (&) #-}
#endif

(^.) :: b -> CylLens a s b t -> a
b ^. lens = lensGet lens b
{-# INLINE (^.) #-}
(%~) :: CylLens a s b t -> (a -> s) -> (b -> t)
(lens %~ f) b = lensSet lens b (f $ lensGet lens b)
{-# INLINE (%~) #-}
(.~) :: CylLens a s b t -> s -> (b -> t)
(lens .~ v) b = lensSet lens b v
{-# INLINE (.~) #-}
(.=) :: CylLens a a' s s -> a' -> State s ()
lens .= v = do {s <- get; put $ s & lens .~ v}
{-# INLINE (.=) #-}
(%=) :: CylLens a a' s s -> (a -> a') -> State s ()
lens %= f = do {s <- get; put $ s & lens %~ f}
{-# INLINE (%=) #-}
view :: CylLens a a' s s' -> Reader s a
view l = ask >>= return . (^. l)
use :: CylLens a a' s s' -> State s a
use l = get >>= return . (^. l)
zoom :: CylLens' s' s -> State s' c -> State s c
zoom l m = do
  s' <- use l
  let (c, s'') = runState m s'
  l .= s''
  return c

-- }}}

-- {{{ Common used lens

class Has1 m a | m -> a where
  _1 :: CylLens' a m

class Has2 m a | m -> a where
  _2 :: CylLens' a m

class Has3 m a | m -> a where
  _3 :: CylLens' a m

class Has4 m a | m -> a where
  _4 :: CylLens' a m

class Has5 m a | m -> a where
  _5 :: CylLens' a m

class Has6 m a | m -> a where
  _6 :: CylLens' a m

instance Has1 ((,) a b) a where
  _1 = lens fst $ \(a, b) c -> (c, b)
  {-# INLINE _1 #-}

instance Has1 ((,,) a b c) a where
  _1 = lens (\(a, _, _) -> a) $ \(a, b, c) d -> (d, b, c)
  {-# INLINE _1 #-}

instance Has1 ((,,,) a b c d) a where
  _1 = lens (\(a, _, _, _) -> a) $ \(a, b, c, d) e -> (e, b, c, d)
  {-# INLINE _1 #-}

instance Has1 ((,,,,) a b c d e) a where
  _1 = lens (\(a, _, _, _, _) -> a) $ \(a, b, c, d, e) f -> (f, b, c, d, e)
  {-# INLINE _1 #-}

instance Has1 ((,,,,,) a b c d e f) a where
  _1 = lens (\(a, _, _, _, _, _) -> a) $ \(a, b, c, d, e, f) g -> (g, b, c, d, e, f)
  {-# INLINE _1 #-}

instance Has2 ((,) a b) b where
  _2 = lens snd $ \(a, b) c -> (a, c)
  {-# INLINE _2 #-}

instance Has2 ((,,) a b c) b where
  _2 = lens (\(_, b, _) -> b) $ \(a, b, c) d -> (a, d, c)
  {-# INLINE _2 #-}

instance Has2 ((,,,) a b c d) b where
  _2 = lens (\(_, b, _, _) -> b) $ \(a, b, c, d) e -> (a, e, c, d)
  {-# INLINE _2 #-}

instance Has2 ((,,,,) a b c d e) b where
  _2 = lens (\(_, b, _, _, _) -> b) $ \(a, b, c, d, e) f -> (a, f, c, d, e)
  {-# INLINE _2 #-}

instance Has2 ((,,,,,) a b c d e f) b where
  _2 = lens (\(_, b, _, _, _, _) -> b) $ \(a, b, c, d, e, f) g -> (a, g, c, d, e, f)
  {-# INLINE _2 #-}

instance Has3 ((,,) a b c) c where
  _3 = lens (\(_, _, c) -> c) $ \(a, b, c) d -> (a, b, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,) a b c d) c where
  _3 = lens (\(_, _, c, _) -> c) $ \(a, b, c, d) e -> (a, b, e, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,,) a b c d e) c where
  _3 = lens (\(_, _, c, _, _) -> c) $ \(a, b, c, d, e) f -> (a, b, f, d, e)
  {-# INLINE _3 #-}

instance Has3 ((,,,,,) a b c d e f) c where
  _3 = lens (\(_, _, c, _, _, _) -> c) $ \(a, b, c, d, e, f) g -> (a, b, g, d, e, f)
  {-# INLINE _3 #-}

instance Has4 ((,,,) a b c d) d where
  _4 = lens (\(_, _, _, d) -> d) $ \(a, b, c, d) e -> (a, b, c, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,) a b c d e) d where
  _4 = lens (\(_, _, _, d, _) -> d) $ \(a, b, c, d, e) f -> (a, b, c, f, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,,) a b c d e f) d where
  _4 = lens (\(_, _, _, d, _, _) -> d) $ \(a, b, c, d, e, f) g -> (a, b, c, g, e, f)
  {-# INLINE _4 #-}

instance Has5 ((,,,,) a b c d e) e where
  _5 = lens (\(_, _, _, _, e) -> e) $ \(a, b, c, d, e) f -> (a, b, c, d, f)
  {-# INLINE _5 #-}

instance Has5 ((,,,,,) a b c d e f) e where
  _5 = lens (\(_, _, _, _, e, _) -> e) $ \(a, b, c, d, e, f) g -> (a, b, c, d, g, f)
  {-# INLINE _5 #-}

instance Has6 ((,,,,,) a b c d e f) f where
  _6 = lens (\(_, _, _, _, _, f) -> f) $ \(a, b, c, d, e, f) g -> (a, b, c, d, e, g)
  {-# INLINE _6 #-}

-- }}}

-- {{{ Handy IO

type StringReader a = State BS.ByteString a

readContents :: StringReader a -> IO a
readContents reader = do
  contents <- BS.getContents
  return $ readFrom contents reader

readFrom :: BS.ByteString -> StringReader a -> a
readFrom s = fst . flip runState s

isLineBreak :: Char -> Bool
isLineBreak c = c == '\n' || c == '\r'

stripLineBreak :: StringReader ()
stripLineBreak = do
  modify $ BS.dropWhile isLineBreak

getLine :: StringReader BS.ByteString
getLine = do
  s <- get
  let (l, s') = BS.span (not . isLineBreak) s
  put s'
  stripLineBreak
  return l

restLines :: StringReader [BS.ByteString]
restLines = do
  s <- get
  put BS.empty
  return $ BS.lines s

getInt :: Num a => StringReader a
getInt = do
  s <- get
  let l' = BS.dropWhile isSpace s
      (d, ll') = BS.span isDigit l'
  put ll'
  return $ case BS.readInt d of
    Just (i, _) -> fromIntegral i
    Nothing -> error $ "Not an integer: " ++ show d

-- }}}

type SolveState = ([Int], [Int])
type SolveStateMap = Map.Map Int SolveState

data PrefixSolveState = PSS {
  _ssm :: SolveStateMap,
  _total :: Int
}
_pssIso :: CylLens' (SolveStateMap, Int) PrefixSolveState
_pssIso = iso (uncurry PSS) (\(PSS a b) -> (a, b))
ssm :: CylLens' SolveStateMap PrefixSolveState
ssm = _pssIso . _1
total :: CylLens' Int PrefixSolveState
total = _pssIso . _2

solve :: [Int] -> [Int]
solve xs = scanl1 (\x y -> (x + y) `mod` modulo)
  $ fst $ runState resultM (Map.singleton 0 ([], [1]))
  where
    modulo = 1000000007
    factor = 1337

    blacklist = map (map (\c -> (ord c) - (ord '0')))
      ["0011", "0101", "1110", "1111"]

    prefixes = xs & scanl (flip (:)) [] & drop 1
    resultM = forM prefixes app

    lastDigits :: CylLens' [Int] SolveState
    lastDigits = _1

    lastCounts :: CylLens' [Int] SolveState
    lastCounts = _2

    p a = (a:) . take 3

    app1 :: Int -> State SolveState ()
    app1 digit = do
      lastDigits %= (p digit)
      (ds, cs) <- get
      let numLastCs = if ds `elem` blacklist then 3 else 4
          newCount = (sum $ take numLastCs cs) `mod` modulo
      lastCounts %= (p newCount)
      return ()

    hashSeq :: [Int] -> [Int]
    hashSeq = drop 1 . scanl (\ph x -> (ph * factor + x + 1) `mod` modulo) 0

    app :: [Int] -> State SolveStateMap Int
    app prefix = prefixResult
      where
        hs = hashSeq prefix

        getPhs :: SolveStateMap -> [(Int, Int, Int)]
        getPhs ssm = prefix
          & zip hs
          & zipWith (\prevH (h, p) -> (prevH, h, p)) (0:hs)

        app' :: (Int, Int, Int) -> State PrefixSolveState ()
        app' (prevH, h, c) = do
          stateMap <- use ssm
          let prevS = stateMap Map.! prevH
              newS = execState (app1 c) prevS
          ssm %= Map.insert h newS
          let cnt = newS ^. lastCounts & head
          total %= (`mod` modulo) . (+cnt)

        prefixResult :: State SolveStateMap Int
        prefixResult = do
          stateMap <- get
          let phs = getPhs stateMap
                & filter (not . (`Map.member` stateMap) . (^. _2))
              m = forM_ phs app'
              pss = execState m (PSS stateMap 0)
          put (pss ^. ssm)
          return (pss ^. total)

main :: IO ()
main = do
  s <- readContents $ do
     m <- getInt
     replicateM m getInt
  solve s & map show & unlines & putStrLn
  return ()

{-# LANGUAGE CPP #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Rank2Types #-}

import Control.Applicative
import Control.Monad
import Data.Char
import Data.Function
import Data.Functor

import qualified Data.Map.Strict as Map
import qualified Data.ByteString.Lazy.Char8 as BS

#if __GLASGOW_HASKELL__ >= 713
import Control.Monad.Trans.State
import Control.Monad.Trans.Reader
import Data.Functor.Identity
#endif

-- {{{ Functors

#if __GLASGOW_HASKELL__ < 713
newtype Identity a = Identity {runIdentity :: a}

instance Functor Identity where
  fmap f (Identity x) = Identity $ f x
#endif

-- }}}

-- {{{ Monads

#if __GLASGOW_HASKELL__ < 713
newtype Reader a b = Reader {runReader :: a -> b}
newtype State s a = State {runState :: s -> (a, s)}

instance Functor (Reader a) where
  fmap f =  Reader . (f . ). runReader
  {-# INLINE fmap #-}

instance Applicative (Reader a) where
  pure = Reader . const
  {-# INLINE pure #-}
  a <*> b = Reader f'
    where
      f1 = runReader a
      f2 = runReader b
      f' = \p -> (f1 p) (f2 p)
  {-# INLINE (<*>) #-}

instance Monad (Reader a) where
  r1 >>= r2 = Reader $ \a -> runReader (r2 $ runReader r1 a) a
  {-# INLINE (>>=) #-}
  return = pure

ask :: Reader a a
ask = Reader id
{-# INLINE ask #-}
local :: (a -> a) -> Reader a b -> Reader a b
local f r = let f' = (runReader r) . f in Reader f'
{-# INLINE local #-}

instance Functor (State s) where
  fmap f st = State $ \s -> let (a, s') = runState st s in (f a, s')

instance Applicative (State s) where
  pure = State . (,)
  {-# INLINE pure #-}
  s1 <*> s2 = State $ \s ->
    let (f, s') = runState s1 s
        (a, s'') = runState s2 s'
    in (f a, s'')

instance Monad (State s) where
  s1 >>= ms2 = State $ \s ->
    let (a, s') = runState s1 s
    in runState (ms2 a) s'
  return = pure

put :: s -> State s ()
put = State . const . ((,) ())
{-# INLINE put #-}
get :: State s s
get = State $ \s -> (s, s)
{-# INLINE get #-}
execState :: State s a -> s -> s
execState st s0 = snd $ runState st s0
#endif

-- }}}

-- {{{ Lens

type CylLens a s b t = forall f. Functor f => (a -> f s) -> b -> f t
type CylLens' a b = CylLens a a b b
lens :: (b -> a) -> (b -> s -> t) -> CylLens a s b t
lens r w g b = w b <$> g (r b)
{-# INLINE lens #-}
iso :: (a -> b) -> (b -> a) -> CylLens' a b
iso f f' = let f'' _ a = f a in lens f' f''
{-# INLINE iso #-}
lensGet :: CylLens a s b t -> b -> a
lensGet lens = getConst . lens Const
{-# INLINE lensGet #-}
lensSet :: CylLens a s b t -> b -> s -> t
lensSet lens b s = runIdentity $ lens (Identity . const s) b
{-# INLINE lensSet #-}

#if __GLASGOW_HASKELL__ < 713
infix 1 &
#endif

infix 8 ^.
infix 4 .=, %=
infixr 4 .~, %~

#if __GLASGOW_HASKELL__ < 713
(&) :: a -> (a -> b) -> b
a & f = f a
{-# INLINE (&) #-}
#endif

(^.) :: b -> CylLens a s b t -> a
b ^. lens = lensGet lens b
{-# INLINE (^.) #-}
(%~) :: CylLens a s b t -> (a -> s) -> (b -> t)
(lens %~ f) b = lensSet lens b (f $ lensGet lens b)
{-# INLINE (%~) #-}
(.~) :: CylLens a s b t -> s -> (b -> t)
(lens .~ v) b = lensSet lens b v
{-# INLINE (.~) #-}
(.=) :: CylLens a a' s s -> a' -> State s ()
lens .= v = do {s <- get; put $ s & lens .~ v}
{-# INLINE (.=) #-}
(%=) :: CylLens a a' s s -> (a -> a') -> State s ()
lens %= f = do {s <- get; put $ s & lens %~ f}
{-# INLINE (%=) #-}
view :: CylLens a a' s s' -> Reader s a
view l = ask >>= return . (^. l)
use :: CylLens a a' s s' -> State s a
use l = get >>= return . (^. l)
zoom :: CylLens' s' s -> State s' c -> State s c
zoom l m = do
  s' <- use l
  let (c, s'') = runState m s'
  l .= s''
  return c

-- }}}

-- {{{ Common used lens

class Has1 m a | m -> a where
  _1 :: CylLens' a m

class Has2 m a | m -> a where
  _2 :: CylLens' a m

class Has3 m a | m -> a where
  _3 :: CylLens' a m

class Has4 m a | m -> a where
  _4 :: CylLens' a m

class Has5 m a | m -> a where
  _5 :: CylLens' a m

class Has6 m a | m -> a where
  _6 :: CylLens' a m

instance Has1 ((,) a b) a where
  _1 = lens fst $ \(a, b) c -> (c, b)
  {-# INLINE _1 #-}

instance Has1 ((,,) a b c) a where
  _1 = lens (\(a, _, _) -> a) $ \(a, b, c) d -> (d, b, c)
  {-# INLINE _1 #-}

instance Has1 ((,,,) a b c d) a where
  _1 = lens (\(a, _, _, _) -> a) $ \(a, b, c, d) e -> (e, b, c, d)
  {-# INLINE _1 #-}

instance Has1 ((,,,,) a b c d e) a where
  _1 = lens (\(a, _, _, _, _) -> a) $ \(a, b, c, d, e) f -> (f, b, c, d, e)
  {-# INLINE _1 #-}

instance Has1 ((,,,,,) a b c d e f) a where
  _1 = lens (\(a, _, _, _, _, _) -> a) $ \(a, b, c, d, e, f) g -> (g, b, c, d, e, f)
  {-# INLINE _1 #-}

instance Has2 ((,) a b) b where
  _2 = lens snd $ \(a, b) c -> (a, c)
  {-# INLINE _2 #-}

instance Has2 ((,,) a b c) b where
  _2 = lens (\(_, b, _) -> b) $ \(a, b, c) d -> (a, d, c)
  {-# INLINE _2 #-}

instance Has2 ((,,,) a b c d) b where
  _2 = lens (\(_, b, _, _) -> b) $ \(a, b, c, d) e -> (a, e, c, d)
  {-# INLINE _2 #-}

instance Has2 ((,,,,) a b c d e) b where
  _2 = lens (\(_, b, _, _, _) -> b) $ \(a, b, c, d, e) f -> (a, f, c, d, e)
  {-# INLINE _2 #-}

instance Has2 ((,,,,,) a b c d e f) b where
  _2 = lens (\(_, b, _, _, _, _) -> b) $ \(a, b, c, d, e, f) g -> (a, g, c, d, e, f)
  {-# INLINE _2 #-}

instance Has3 ((,,) a b c) c where
  _3 = lens (\(_, _, c) -> c) $ \(a, b, c) d -> (a, b, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,) a b c d) c where
  _3 = lens (\(_, _, c, _) -> c) $ \(a, b, c, d) e -> (a, b, e, d)
  {-# INLINE _3 #-}

instance Has3 ((,,,,) a b c d e) c where
  _3 = lens (\(_, _, c, _, _) -> c) $ \(a, b, c, d, e) f -> (a, b, f, d, e)
  {-# INLINE _3 #-}

instance Has3 ((,,,,,) a b c d e f) c where
  _3 = lens (\(_, _, c, _, _, _) -> c) $ \(a, b, c, d, e, f) g -> (a, b, g, d, e, f)
  {-# INLINE _3 #-}

instance Has4 ((,,,) a b c d) d where
  _4 = lens (\(_, _, _, d) -> d) $ \(a, b, c, d) e -> (a, b, c, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,) a b c d e) d where
  _4 = lens (\(_, _, _, d, _) -> d) $ \(a, b, c, d, e) f -> (a, b, c, f, e)
  {-# INLINE _4 #-}

instance Has4 ((,,,,,) a b c d e f) d where
  _4 = lens (\(_, _, _, d, _, _) -> d) $ \(a, b, c, d, e, f) g -> (a, b, c, g, e, f)
  {-# INLINE _4 #-}

instance Has5 ((,,,,) a b c d e) e where
  _5 = lens (\(_, _, _, _, e) -> e) $ \(a, b, c, d, e) f -> (a, b, c, d, f)
  {-# INLINE _5 #-}

instance Has5 ((,,,,,) a b c d e f) e where
  _5 = lens (\(_, _, _, _, e, _) -> e) $ \(a, b, c, d, e, f) g -> (a, b, c, d, g, f)
  {-# INLINE _5 #-}

instance Has6 ((,,,,,) a b c d e f) f where
  _6 = lens (\(_, _, _, _, _, f) -> f) $ \(a, b, c, d, e, f) g -> (a, b, c, d, e, g)
  {-# INLINE _6 #-}

-- }}}

-- {{{ Handy IO

type StringReader a = State BS.ByteString a

readContents :: StringReader a -> IO a
readContents reader = do
  contents <- BS.getContents
  return $ readFrom contents reader

readFrom :: BS.ByteString -> StringReader a -> a
readFrom s = fst . flip runState s

isLineBreak :: Char -> Bool
isLineBreak c = c == '\n' || c == '\r'

stripLineBreak :: StringReader ()
stripLineBreak = do
  modify $ BS.dropWhile isLineBreak

getLine :: StringReader BS.ByteString
getLine = do
  s <- get
  let (l, s') = BS.span (not . isLineBreak) s
  put s'
  stripLineBreak
  return l

restLines :: StringReader [BS.ByteString]
restLines = do
  s <- get
  put BS.empty
  return $ BS.lines s

getInt :: Num a => StringReader a
getInt = do
  s <- get
  let l' = BS.dropWhile isSpace s
      (d, ll') = BS.span isDigit l'
  put ll'
  return $ case BS.readInt d of
    Just (i, _) -> fromIntegral i
    Nothing -> error $ "Not an integer: " ++ show d

-- }}}

type SolveState = ([Int], [Int])
type SolveStateMap = Map.Map Int SolveState

data PrefixSolveState = PSS {
  _ssm :: SolveStateMap,
  _total :: Int
}
_pssIso :: CylLens' (SolveStateMap, Int) PrefixSolveState
_pssIso = iso (uncurry PSS) (\(PSS a b) -> (a, b))
ssm :: CylLens' SolveStateMap PrefixSolveState
ssm = _pssIso . _1
total :: CylLens' Int PrefixSolveState
total = _pssIso . _2

solve :: [Int] -> [Int]
solve xs = scanl1 addMod $ fst $ runState resultM (Map.singleton 0 ([], [1]))
  where
    modulo = 1000000007
    factor = 1337

    addMod x y = (x + y) `mod` modulo

    blacklist = map (map (\c -> (ord c) - (ord '0')))
      ["0011", "0101", "1110", "1111"]

    prefixes = xs & scanl (flip (:)) [] & drop 1
    resultM = forM prefixes app

    lastDigits :: CylLens' [Int] SolveState
    lastDigits = _1

    lastCounts :: CylLens' [Int] SolveState
    lastCounts = _2

    p a = (a:) . take 3

    app1 :: Int -> State SolveState ()
    app1 digit = do
      lastDigits %= (p digit)
      (ds, cs) <- get
      let numLastCs = if ds `elem` blacklist then 3 else 4
          newCount = (foldl addMod 0 $ take numLastCs cs) `mod` modulo
      lastCounts %= (p newCount)
      return ()

    hashSeq :: [Int] -> [Int]
    hashSeq = drop 1 . scanl (\ph x -> (ph * factor + x + 1) `mod` modulo) 0

    app :: [Int] -> State SolveStateMap Int
    app prefix = prefixResult
      where
        hs = hashSeq prefix

        getPhs :: SolveStateMap -> [(Int, Int, Int)]
        getPhs ssm = prefix
          & zip hs
          & zipWith (\prevH (h, p) -> (prevH, h, p)) (0:hs)

        app' :: (Int, Int, Int) -> State PrefixSolveState ()
        app' (prevH, h, c) = do
          stateMap <- use ssm
          let prevS = stateMap Map.! prevH
              newS = execState (app1 c) prevS
          ssm %= Map.insert h newS
          let cnt = newS ^. lastCounts & head
          total %= (`mod` modulo) . (+cnt)

        prefixResult :: State SolveStateMap Int
        prefixResult = do
          stateMap <- get
          let phs = getPhs stateMap
                & filter (not . (`Map.member` stateMap) . (^. _2))
              m = forM_ phs app'
              pss = execState m (PSS stateMap 0)
          put (pss ^. ssm)
          return (pss ^. total)

main :: IO ()
main = do
  s <- readContents $ do
     m <- getInt
     replicateM m getInt
  solve s & map show & unlines & putStrLn
  return ()


-- https://codeforces.com/contest/1679/problem/D
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DatatypeContexts #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Strict #-}
{-# LANGUAGE TupleSections #-}

import Control.Arrow ((>>>))
import Control.Monad (
    MonadPlus (mplus),
    foldM_,
    forM_,
    guard,
    join,
    replicateM,
    replicateM_,
 )
import qualified Control.Monad.ST.Strict as ST
import qualified Control.Monad.State.Strict as S

import qualified Data.Array as A
import qualified Data.Array.MArray.Safe as MA
import qualified Data.Array.ST.Safe as STA
import qualified Data.Array.Unboxed as UA

import Data.Bits
import qualified Data.ByteString.Char8 as B8
import Data.Char
import Data.Int

import Data.Function (on)
import Data.Functor ((<&>))
import Data.Bifunctor (bimap)
import Data.Maybe (fromJust, fromMaybe, isJust)

import qualified Data.IntMap as IM
import qualified Data.IntSet as IS
import qualified Data.List   as L
import Data.List (
    elemIndices,
    find,
    findIndices,
    intersect,
    isPrefixOf,
    nub,
    sort,
    sortOn,
 )
import qualified Data.Map as M
import qualified Data.Set as S

import Control.Monad.Cont (MonadIO (liftIO))
import Data.IORef (modifyIORef, newIORef, readIORef)
import GHC.IO.Handle (hDuplicateTo)
import System.IO (
    IOMode (ReadMode, WriteMode),
    openFile,
    stdin,
    stdout,
 )
import System.Posix.Internals (puts)
import Text.Printf (printf)

-- import Debug.Trace (trace, traceM, traceShowM)
-- debug = flip trace

readIntB8 :: B8.ByteString -> Int
readIntB8 = B8.readInt >>> (fst . fromJust)

readIntB8s :: B8.ByteString -> [Int]
readIntB8s = B8.words >>> map (B8.readInt >>> (fst . fromJust))

readIntegerB8 :: B8.ByteString -> Integer
readIntegerB8 = B8.readInteger >>> (fst . fromJust)

readIntegerB8s :: B8.ByteString -> [Integer]
readIntegerB8s = B8.words >>> map (B8.readInteger >>> (fst . fromJust))

modifyArray :: (MA.MArray a e m, MA.Ix i) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = do
    value <- MA.readArray arr ix
    MA.writeArray arr ix $ f value

putsYesNo :: Bool -> IO ()
putsYesNo value = do
    let result :: String =
            if value
                then "Yes"
                else "No"
    printf "%s\n" result

{- END OF GENERAL -}

solve :: (Int, Int, Int) -> (Int, Int, Int)
solve (a, b, c) = (a + b + c, b + c, c)

main :: IO ()
main = do
    t <- B8.getLine <&> readIntB8
    replicateM_ t $ do
        [a, b, c] <- B8.getLine <&> readIntB8s
        let (x, y, z) = solve (a, b, c)
        printf "%d %d %d\n" x y z

parse :: String -> [(Int, Int, Int)]
parse input =  case lines input of
    [] -> undefined
    (w:ws) -> parseN (read w) ws
    where
        parseLine :: String -> (Int, Int, Int)
        parseLine = (\[a, b, c] -> (a, b, c)) . map read . take 3 . words
        parseN :: Int -> [String] -> [(Int, Int, Int)]
        parseN t = map parseLine . take t

solve :: [(Int, Int, Int)] -> [(Int, Int, Int)]
solve = map (\(a, b, c) -> (a+b+c, b+c, c))

format :: [(Int, Int, Int)] -> String
format = unlines . map (unwords . (\(x, y, z) -> [show x, show y, show z]))

main :: IO ()
main = interact (format . solve . parse)

import Control.Monad (replicateM_)

solve :: Integer -> Integer -> Integer -> [Integer]
solve a b c = [a + b + c, b + c, c]

main = do
    n <- readLn :: IO Int
    replicateM_ n $ do
        [a, b, c] <- map read . words <$> getLine :: IO [Integer]
        putStrLn $ unwords $ map show $ solve a b c

mainLoop 0 = return ()
mainLoop t = do line <- getLine
                let [a, b, c] = map (read :: String -> Int) (words line)
                putStrLn (unwords [show (a + b + c), show (b + c), show c])
                mainLoop (t - 1)

main = do t <- (readLn :: IO Int)
          mainLoop t

main :: IO ()
main = do
	n <- getLine
	let number = read n :: Int
	solve number number
	return ()

solve :: Int -> Int -> IO ()
solve number 0 = return ()
solve number current = 	do
				line <- getLine
				let ws = words line
				let a = (read $ head ws) :: Int
				let b = (read $ head $ tail ws) :: Int
				let c = (read $ head $ tail $ tail ws) :: Int
				let x = a + b + c
				let y = b + c
				let z = c
				putStrLn $ (show x) ++ " " ++ (show y) ++ " " ++ (show z)
				solve number (current - 1)

import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as C
import Data.ByteString.Builder
import System.IO

parseInt :: C.ByteString -> Int
parseInt = fst . fromJust . C.readInt

getInts :: IO [Int]
getInts = map parseInt . C.words <$> C.getLine

putInts :: [Int] -> Builder
putInts [] = charUtf8 '\n'
putInts (x : xs) = intDec x <> charUtf8 ' ' <> putInts xs

main :: IO ()
main = do
  [t] <- getInts
  output <- fmap mconcat $ replicateM t $ do
    [a, b, c] <- getInts
    let k = (c - a) `div` b + 1
    return $ putInts [k * b + a, b, c]
  hPutBuilder stdout output

parse :: String -> [(Int, Int, Int)]
parse input =  case lines input of
    [] -> undefined
    (w:ws) -> parseN (read w) ws
    where
        parseLine :: String -> (Int, Int, Int)
        parseLine = (\[a, b, c] -> (a, b, c)) . map read . take 3 . words
        parseN :: Int -> [String] -> [(Int, Int, Int)]
        parseN t = map parseLine . take t

solve :: [(Int, Int, Int)] -> [(Int, Int, Int)]
solve = map (\(a, b, c) -> (a+b+c, a+b, c))

format :: [(Int, Int, Int)] -> String
format = unlines . map (unwords . (\(x, y, z) -> [show x, show y, show z]))

main :: IO ()
main = interact (format . solve . parse)

parse :: String -> (Int, Int, Int)
parse = (\[a, b, c] -> (a, b, c)) . map read . take 3 . words

solve :: (Int, Int, Int) -> (Int, Int, Int)
solve (a, b, c) = (a+b+c, a+b, c)

format :: (Int, Int, Int) -> String
format (x, y, z) = unwords $ map show [x, y, z]

main :: IO ()
main = interact (format . solve . parse)

import Control.Monad (replicateM_)

solve :: Int -> Int -> Int -> [Int]
solve a b c = [a + b + c, b + c, c]

main = do
    n <- readLn :: IO Int
    replicateM_ n $ do
        [a, b, c] <- map read . words <$> getLine :: IO [Int]
        print $ unwords $ map show $ solve a b c