import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import qualified Data.List             as L
import qualified Data.Map              as M
import           Data.Maybe
import qualified Data.Set              as S
import qualified Data.Tuple            as T


readInt' :: BS.ByteString -> Int
readInt' = fst . fromJust . BS.readInt

-- lcs :: BS.ByteString
--     -> BS.ByteString
--     -> Int
lcs :: (Ord a, Num a) => BS.ByteString -> BS.ByteString -> M.Map (Int, Int) a
lcs str1 str2 =
    L.foldl' (\ acc (i, j) ->
                  if BS.index str1 (i - 1) == BS.index str2 (j - 1)
                  then M.insert (i, j)
                           (M.findWithDefault 0 (i - 1, j - 1) acc + 1)
                           acc
                  else M.insert (i, j)
                           (max (M.findWithDefault 0 (i - 1, j) acc)
                                (M.findWithDefault 0 (i, j - 1) acc))
                           acc)
         (M.singleton (0, 0) 0)
         [(i, j) | i <- [1..BS.length str1], j <- [1..BS.length str2]]


main :: IO ()
main = do
  n <- readLn :: IO Int
  forM_ [1..n] $ \_ -> do
         str1 <- BS.getLine
         str2 <- BS.getLine
         let dp = lcs str1 str2
         putStrLn (show $ M.findWithDefault 0 (BS.length str1, BS.length str2)
                        dp)