Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrep1(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;


int dp[1000][1000];

int getLCS(string* s1, string* s2, int s1i, int s2i)
{
	int ret;
	int cand1, cand2;

	if (s1i < 0 || s2i < 0) {
		return 0;
	}
	else if (dp[s1i][s2i] != -1) ret = dp[s1i][s2i];
	else if ((*s1)[s1i] == (*s2)[s2i]) {
		ret = getLCS(s1, s2, s1i - 1, s2i - 1) + 1;
	}
	else {
		cand1 = getLCS(s1, s2, s1i, s2i - 1);
		cand2 = getLCS(s1, s2, s1i - 1, s2i);
		ret = max(cand1, cand2);
	}
	dp[s1i][s2i] = ret;

	return ret;
}

int main()
{
	int q;
	int ans;
	string s1, s2;

	cin >> q;
	rep(i, q) {
		rep(j, 1000) {
			rep(k, 1000) dp[j][k] = -1;
		}
		cin >> s1 >> s2;
		ans = getLCS(&s1, &s2, s1.length() - 1, s2.length() - 1);
		cout << ans << endl;
	}

	return 0;
}