Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	results := []int{}
	for i := 0; i < n; i++ {
		results = append(results, resolveInstance())
	}
	for _, v := range results {
		fmt.Println(v)
	}
	return
}

func resolveInstance() int {
	x, y := scanString(sc), scanString(sc)
	lx, ly := len(x), len(y)
	dp := make([][]int, lx+1)
	dp[0] = make([]int, ly+1)
	for i := 1; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
		dp[i][0] = dp[i-1][0]
		for j := 1; j <= ly; j++ {
			dp[i][j] = dp[i-1][j]
			if dp[i][j] < dp[i][j-1] {
				dp[i][j] = dp[i][j-1]
			}
			if x[i-1] == y[j-1] {
				cL := dp[i-1][j-1] + 1
				if dp[i][j] < cL {
					dp[i][j] = cL
				}
			}
		}
	}
	return dp[lx][ly]
}

const (
	remove = 0 + iota
	match
)

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>

const int Size = 1000;
int dp[Size + 1][Size + 1];
std::string x;
std::string y;

int calc(int m, int n)
{
	int ans = 0;

	if (dp[m][n] != -1) {
		return dp[m][n];
	}

	if (m == 0 || n == 0) {
		return 0;
	}

	if (x[m - 1] == y[n - 1]) {
		ans = calc(m - 1, n - 1) + 1;
		dp[m][n] = ans;
		return ans;
	}

	ans = std::max(calc(m, n - 1), calc(m - 1, n));
	dp[m][n] = ans;
	return ans;
}


int main()
{
	int q;
	std::vector<int> ans;
	std::cin >> q;

	for (int i = 0; i < q; i++) {
		std::cin >> x >> y;
		for (int j = 0; j < Size + 1; j++) {
			for (int k = 0; k < Size + 1; k++) {
				dp[j][k] = -1;
			}
		}
		int temp = calc(x.size(), y.size());
		ans.push_back(temp);
	}

	for (unsigned int i = 0; i < ans.size(); i++) {
		std::cout << ans[i] << std::endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int q;
string x, y;
int dp[1111][1111];

void solve() {
   for (int i = 1; i <= x.size(); i++) {
      for (int j = 1; j <= y.size(); j++) {
         if (x[i] == y[j]) {
            dp[i][j] = dp[i-1][j-1] + 1;
         } else {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
         }
      }
   }
   cout << dp[x.size()][y.size()] << endl;
}

int main() {
   cin >> q;
   while (q--) {
      cin >> x >> y;
      solve();
   }

   return 0;
}

C++: #include <iostream>
using namespace std;

int max(int a, int b) { return a < b ? b : a; }

int lcs(string x, string y) {
    int c[1001][1001] = {0};
    int m = x.size();
    int n = y.size();
    int maxl = 0;
    x = ' ' + x;
    y = ' ' + y;
    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (x[i] == y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
            maxl = max(maxl, c[i][j]);
        }
    }

    return maxl;
}

int main() {

    int n;
    cin >> n;
    string s1, s2;
    for (int i = 0; i < n; ++i) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }

    return 0;
}

C++: #include <iostream>

int main()
{
    int num;
    std::cin >> num;
    std::string a, b;
    while (std::cin >> a >> b) 
    {
        int m, n;
        m = a.size();
        n = b.size();
        a = ' ' + a;
        b = ' ' + b;
        int maxl = 0;
        long c[m + 1][n + 1];
        for (int i = 0; i <= m; i++) c[i][0] = 0;
        for (int i = 1; i <= n; i++) c[0][i] = 0;
        for (int i = 1;  i <= m; i++) 
        {
            for (int  j = 1; j <= n; j++)
            {
                if (a[i] == b[j])
                    c[i][j] = c[i - 1][j - 1] + 1;
                else if (c[i - 1][j] >= c[i][j - 1])
                    c[i][j] = c[i - 1][j];
                else 
                    c[i][j] = c[i][j - 1];
                maxl = (maxl >= c[i][j]) ? maxl : c[i][j];
            }
        }
        std::cout << maxl << '\n';
    }
}

C++: #include<bits/stdc++.h>
using namespace std;


int main() {
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        string s, t;
        cin >> s >> t;
        int sl = s.size(), tl = t.size();
        int dp[1010][1010];
        dp[0][0] = 0;
        for (int j = 1; j <= sl; ++j) {
            for (int k = 1; k <= tl; ++k) {
                if (s[j - 1] == t[k - 1]) {
                    dp[j][k] = dp[j - 1][k - 1] + 1;
                }
                else {
                    dp[j][k] = max(dp[j - 1][k], dp[j][k - 1]);
                }
            }
        }
        cout << dp[sl][tl] << "\n";
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vb=vector<bool>;
using pii=pair<int,int>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int Q;
    cin>>Q; ;
    rep(c,0,Q){
        string X,Y;
        cin>>X>>Y;
        int xs=X.size()+1;
        int ys=Y.size()+1;
        int dp[xs][ys];
        rep(i,0,xs)dp[i][0]=0;
        rep(j,0,ys)dp[0][j]=0;

        rep(i,1,xs){
            rep(j,1,ys){
                if(X[i-1]==Y[j-1])dp[i][j]=dp[i-1][j-1]+1;
                else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
            }
        }
        cout<<dp[xs-1][ys-1]<<endl;
    }
    return 0;
}