
$dp = []

def solve(str1, str2)  
  arr1 = str1.split(//)
  arr2 = str2.split(//)
  sz1 = str1.length    
  sz2 = str2.length
  (0..1010).each do |i|
    (0..1010).each do |j|
      $dp[i][j] = 0
    end
  end
  (1..sz1).each do |i|
    (1..sz2).each do |j|
      if arr1[i - 1] == arr2[j - 1]
        $dp[i][j] = $dp[i - 1][j - 1] + 1
      else
        $dp[i][j] = [$dp[i - 1][j], $dp[i][j - 1]].max  
      end
    end
  end
  $dp[sz1][sz2]
end

def main
  t = gets.chomp.to_i
  (0..1010).each { |x| $dp << Array.new(1010, 0)}
  (1..t).each do |ca|
    str1 = gets.chomp
    str2 = gets.chomp
    puts solve(str1, str2)  
  end
end

main