# encoding: utf-8                                                                                                                                                                

def solve(str1, str2)
  arr1 = str1.split(//)
  arr2 = str2.split(//)
  sz1 = str1.length  
  sz2 = str2.length
  res = []
  (0..sz1).each do |i|
    res << Array.new(sz2 + 1, 0)
  end

  (1..sz1).each do |i|
    (1..sz2).each do |j|
      if arr1[i - 1] == arr2[j - 1]
        res[i][j] = res[i - 1][j - 1] + 1
      else
        res[i][j] = [res[i - 1][j], res[i][j - 1]].max
      end
    end
  end
  res[sz1][sz2]
end

def main
  t = gets.chomp.to_i
  (1..t).each do |ca|
    str1 = gets.chomp
    str2 = gets.chomp
    puts solve(str1, str2)
  end
end

main