import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

void main(){
    int q = readln.chomp.to!int;
    string x, y;

    int ans;

    foreach(qi ; 0 .. q){
        x = readln.chomp;
        y = readln.chomp;

        ans = computeLCS(x, y);

        writeln(ans);
    }
}

int computeLCS(string x, string y){
    int n = x.length;
    int m = y.length;

    auto dp = new int[][](n + 1, m + 1);

    foreach(i ; 1 .. n + 1){
        foreach(j ; 1 .. m + 1){
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

            if (x[i - 1] == y[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
        }
    }

    return dp[n][m];
}

void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}