import scala.io.StdIn.{readInt, readLine};

object Main {
    def main(args: Array[String]): Unit = {
        val n = readInt;
        for (i <- (0 until n)) {
            val a = readLine;
            val b = readLine;
            println(lcs(a, b).length);
        }
    }
    def lcs(a: String, b: String): String = {
        val arr = Array.ofDim[String](a.length + 1, b.length + 1);
        for (i <- (0 to a.length)) { arr(i)(0) = ""};
        for (i <- (0 to b.length)) { arr(0)(i) = "" };
        def go(row: Int, col: Int): String = {
            if (arr(row)(col) != null) {
                arr(row)(col)
            } else {
                val c1 = go(row - 1, col);
                val c2 = go(row, col - 1);
                val c3 = go(row - 1, col - 1);
                arr(row)(col) = if (a(row - 1) == b(col - 1)) {
                    max(c1, c2, c3 + a(row - 1));
                } else {
                    max(c1, c2, c3);
                }
                arr(row)(col); 
            }
        }
        go(a.length, b.length);
    }
    
    def max(a: String, b: String, c: String): String = {
        val lenA = a.length; val lenB = b.length; val lenC = c.length;
        if (lenA > lenB) {
            if (lenC > lenA) c else a;
        } else {
            if (lenC > lenB) c else b;
        }
    }
}
