-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import Data.Bits

f :: Int -> Int -> Int
f x y = case (x + y) `quotRem` 10 of
          (a,b) -> a + b

gen :: Int -> U.Vector Int
gen a = U.iterateN 64 (\x -> f x x) a

computed :: V.Vector (U.Vector Int)
computed = V.fromList $ map gen [0..9]

pow' :: Int -> Int -> Int
pow' a n = foldr f 0 [ if bit i then (computed V.! a) U.! i else 0 | i <- [0..63]]

main = do
  m <- readLn
  edges <- U.replicateM m $ do
    [d,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (pow' d c)
  print $ U.foldr f 1 edges
