let lcs x y =
  let m = String.length x in
  let n = String.length y in
  let dp = Array.make_matrix (m+1) (n+1) 0 in
  for i = 1 to m do
    for j = 1 to n do
      dp.(i).(j) <- if x.[i-1] = y.[j-1] then dp.(i-1).(j-1) + 1 else if dp.(i-1).(j) > dp.(i).(j-1) then dp.(i-1).(j) else dp.(i).(j-1)
    done
  done;
  dp.(m).(n)

let () =
  let q = read_int () in
  let rec doit i =
    if i < q then begin
      let x = read_line () in
      let y = read_line () in
      Printf.printf "%d\n" (lcs x y);
      doit (i + 1)
    end
  in
  doit 0