function Main(input) {
    var l = 1;
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var q = parseInt(input[0][0], 10);

    for (var k = 0; k < q; k++){
        var X = input[l][0].split("");
        var Y = input[l + 1][0].split("");

        var arr_dp = [];
        for (var j = 0; j <= Y.length; j++){
            arr_dp.push([]);
            arr_dp[j][0] = 0;
        }
        for (var i = 0; i <= X.length; i++){
            arr_dp[0][i] = 0;
        }
        for (var j = 0; j < Y.length; j++){
            for (var i = 0; i < X.length; i++){
                if (X[i] === Y[j]) arr_dp[j + 1][i + 1] = arr_dp[j][i] + 1;
                else arr_dp[j + 1][i + 1] = Math.max(arr_dp[j + 1][i], arr_dp[j][i + 1]);
            }
        }
        console.log(arr_dp[j][i]);
        l+= 2;
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 
