function getLcs(strX, strY) {
    const sizeX = strX.length;
    const sizeY = strY.length;
    strX = ' ' + strX;
    strY = ' ' + strY;

    const com = [];
    for (let i = 0; i <= sizeX; i++) {
        for (let ji = 0; ji <= sizeY; ji++) {
            if(!com[i]) com[i] = [];
            com[i][ji] = 0;
        }
    }

    for (let i = 1; i <= sizeX; i++) {
        for (let ji = 1; ji <= sizeY; ji++) {

            if (strX[i] === strY[ji]) {
                com[i][ji] = com[i - 1][ji - 1] + 1;
            } else if (com[i - 1][ji] >= com[i][ji - 1]) {
                com[i][ji] = com[i - 1][ji];
            } else {
                com[i][ji] = com[i][ji - 1];
            }
        }
    }
    return com[sizeX][sizeY];
}


function main(_stdin) {
    const stdin = _stdin.split('\n');
    let q = parseInt(stdin.shift(), 10);

    while (q) {
        console.log(getLcs(stdin.shift(), stdin.shift()));
        q--;
    }
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));

