
def lcs(s1, s2)
  x = s1.length
  y = s2.length
  maxl = 0
  s1 = " " + s1
  s2 = " " + s2
  c = Array.new(1000, Array.new(1000, 0))

  ind_1 = 1
  while ind_1 <= x do
    ind_2 = 1
    while ind_2 <= y
      if x < ind_2
        break
      end
      if s1[ind_1] == s2[ind_2]
        c[ind_1][ind_2] = c[ind_1-1][ind_2-1] + 1
      elsif c[ind_1][ind_2-1] <= c[ind_1-1][ind_2]
        c[ind_1][ind_2] = c[ind_1-1][ind_2]
      else
        c[ind_1][ind_2] = c[ind_1][ind_2-1]
      end
      maxl = [maxl, c[ind_1][ind_2]].max
      ind_2 += 1
    end
    ind_1 += 1
  end
  maxl
end

ans = []
count = gets.chomp.to_i

count.times do
  s1 = gets.chomp
  s2 = gets.chomp
  ans << lcs(s1, s2)
end

puts ans