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<algorithm>
#include<string>

using namespace std;

int lcs (string x, string y) {

    int m, n, c[1001][1001], i, j, maxl = 0;

    m = x.size();
    n = y.size();

    x = ' ' + x;
    y= ' ' + y;

    for (i = 0; i <= m; i++) {
        c[i][0] = 0;
    }
    for (j = 1; j <= n; j++) {
        c[0][j] = 0;
    }

    for (i = 1; i <= m; i++) {
            for (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, i;
    string x, y;

    cin >> N;

    for (i = 0; i < N; i++) {
        cin >> x >> y;
        cout << lcs (x, y) << endl;

    }

    return 0;

}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

void solve(string s1, string s2) {
    vector<int> dp[s1.size() + 1];
    vector<int> tmp(s2.size() + 1, 0);
    rep(i, s1.size() + 1) {
        dp[i] = tmp;
    }
    rep(i, s1.size() + 1) {
        rep(j, s2.size() + 1) {
            if(i == 0 || j == 0) {
                continue;
            } else {
                if(s1[i-1] == s2[j-1]) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                }
                dp[i][j] = max(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
            }
        }
    }
    // rep(i, s1.size() + 1) {
    //     rep(j, s2.size() + 1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[s1.size()][s2.size()] << endl;
}

int main(){
    int n; cin >> n;
    rep(i, n) {
        string s1, s2; cin >> s1 >> s2;
        solve(s1, s2);
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int q;
string x, y;
int m, n;
int a[1000][1000];
int main()
{
	cin >> q;
	for(int i=0; i<q; i++)
	{
		cin >> x >> y;
		m=x.size();
		n=y.size();
		if(x[0]==y[0])
		{
			a[0][0]=1;
		}
		else
		{
			a[0][0]=0;
		}
		for(int j=1; j<m+n-1; j++)
		{
			if((j<n)&&((x[0]!=y[j])&&(a[0][j-1]==0)))
			{
				a[0][j]=0;
			}
			else if(j<m)
			{
				a[0][j]=1;
			}
			if((j<m)&&((x[j]!=y[0])&&(a[j-1][0]==0)))
			{
				a[j][0]=0;
			}
			else if(j<m)
			{
				a[j][0]=1;
			}
			for(int k=max(1, j-n+1); k<min(j, m); k++)
			{
				if(x[k]==y[j-k])
				{
					a[k][j-k]=a[k-1][j-k-1]+1;
				}
				else
				{
					a[k][j-k]=max(a[k-1][j-k], a[k][j-k-1]);
				}
			}
		}
		cout << a[m-1][n-1] << endl;
	}
	return 0;
}

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

#define MAX 150
#define MAXL 1000

int C[MAXL + 1][MAXL + 1];

int lec(string X, string Y)
{
	int XL = X.length();
	int YL = Y.length();
	X = ' ' + X;
	Y = ' ' + Y;
	for (int i = 0; i <=XL; i++)
		C[i][0] = 0;
	for (int i = 0; i <=YL; i++)
		C[0][i] = 0;
	for (int i = 1; i <=XL; i++)
	{
		for (int j = 1; j <=YL; j++)
		{
			if (X[i] == Y[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];
			}
		}
	}
	return C[XL][YL];
}

int main()
{
	int q;
	string x, y;
	cin >> q;
	for (int i = 0; i<q; i++)
	{
		cin >> x >> y;
		cout << lec(x, y) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
    using namespace std;
int lcs(string x,string y){
    int c[1010][1010];
    int m = x.size();
    int n = y.size();
    int maxl=0;
    x = ' '+x;
    y = ' '+y;
    for (int i=1; i<=m; i++) {
        c[i][0] = 0;
    }
    for(int j=1;j<=n;j++){
        c[0][j] = 0;
    }

    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 q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	std::string X, Y;
	int q;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	std::getline(ifs, X);
#else
	std::getline(std::cin, X);
#endif
	q = std::stoi(X);

	for(int i = 0; i < q; i++){
		std::vector<std::vector<int> > dp;
#if INPUT_FROM_FILE
		std::getline(ifs, X);
		std::getline(ifs, Y);
#else
		std::getline(std::cin, X);
		std::getline(std::cin, Y);
#endif
		dp.resize(X.size() + 1);
		for(int i = 0; i < dp.size(); i++){
			dp[i].resize(Y.size() + 1, 0);
		}

		for(int i = 0; i < X.size(); i++){
			for(int j = 0; j < Y.size(); j++){
				if(X[i] == Y[j]){
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
				else{
					dp[i + 1][j + 1] = std::max(dp[i + 1][j], dp[i][j + 1]);
				}
			}
		}
		std::cout << dp[X.size()][Y.size()] << std::endl;
	}
	return 0;
}

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

int q;
string X,Y;
int L[1001][1001];

int max(int i,int j) {return i > j ? i : j;}

int getL(int i,int j) {
	if(L[i][j] != -1) return L[i][j];

	int res;

	if(i == 0 || j == 0) res = 0;
	else if(X[i - 1] == Y[j - 1]) res = 1 + getL(i - 1,j - 1);
	else res = max(getL(i,j - 1),getL(i - 1,j));

	L[i][j] = res;
	return res;
}

int main() {

	cin >> q;
	for(int i = 0;i < q;i++) {
		cin >> X >> Y;
		for(int j = 0;j <= X.size();j++) {
			for(int k = 0;k <= Y.size();k++) L[j][k] = -1;
		}
		cout << getL(X.size(),Y.size()) << endl;
	}
}