
def lcs(s1, s2)
  x = s1.length
  y = s2.length

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

  i = 1
  while i <= x do
    j = 1
    while j <= y do
      if s1[i] == s2[j]
        c[i][j] = c[i-1][j-1] + 1
      else
        c[i][j] = [c[i-1][j], c[i][j-1]].max
      end

      if maxl < c[i][j]
        maxl = c[i][j]
      end

      j += 1
    end
    i += 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