def catch(a,b,dp,x,y)
  if dp[x-1][y]<dp[x][y-1] then
    dp[x][y]=dp[x][y-1]
  elsif dp[x-1][y]>dp[x][y-1]
    dp[x][y]=dp[x-1][y]
  else
    dp[x][y]=dp[x-1][y]
    if a==b then
      dp[x][y]+=1
    end
  end
end



n=gets.to_i
arr=Array.new
n.times do |i|
  a=gets.chomp!.split("")
  b=gets.chomp!.split("")
  dp=Array.new(a.length+1){Array.new(b.length+1,0)}
  1.upto(a.length) do |x|
     1.upto(b.length) do |y|
      catch(a[x-1],b[y-1],dp,x,y)
    end
  end
  arr << dp[-1][-1]
  a.clear
  b.clear
end
for x in arr do
  print x,"\n"
end
