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

  ind_1 = 1
  while ind_1 <= y do
    ind_2 = 1
    while ind_2 <= x do
      if y < ind_2
        c[ind_1][ind_2] = [c[ind_1-1][ind_2], c[ind_1][ind_2-1]].max
      elsif s1[ind_1] == s2[ind_2]
        c[ind_1][ind_2] = c[ind_1-1][ind_2-1] + 1
      else
        c[ind_1][ind_2] = [c[ind_1-1][ind_2], c[ind_1][ind_2-1]].max
      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