import scala.io.StdIn.{readInt, readLine};
import scala.annotation.tailrec;
object Main {
    def main(args: Array[String]): Unit = {
        (0 until readInt).foreach { i =>
            val y = readLine;
            val x = readLine;
            println(longestCommonSubsequence(y, x));
        }
    }
    def longestCommonSubsequence(strY: String, strX: String): Int = {
        val sizeX = strX.length;
        val sizeY = strY.length;
        val arr = Array.ofDim[Int](sizeY + 1, sizeX + 1);
        (1 to sizeY).foreach { y => (1 to sizeX).foreach { x => arr(y)(x) = -1}}
        def go(y: Int, x: Int): Int = arr(y)(x) match {
            case -1 => {
                val lcs1 = go(y - 1, x - 1);
                val lcs2 = go(y - 1, x);
                val lcs3 = go(y, x - 1);
                arr(y)(x) = if (strX(x - 1) == strY(y - 1)) {
                    max(lcs1 + 1, lcs2, lcs3);
                } else  {
                    max(lcs1, lcs2, lcs3);
                }
                arr(y)(x);
            }
            case lcs => lcs;
        }
        go(sizeY, sizeX);
    }

    def max(a: Int, b: Int, c: Int): Int = {
        if (a > b)
            if (a > c) a else c;
        else
            if (b > c) b else c;
    }
}
