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<bits//stdc++.h>
using namespace std;
int dp[160][1010][1010];


int main(){
    int q;
    cin >> q;
    string a[q],b[q];
    for(int i = 0; i < q; i++){
        cin >> a[i] >> b[i]; 
    }

    for(int i = 0; i < q; i++){
        for(int j = 0; j < a[i].size(); j++){
            for(int k = 0; k < b[i].size(); k++){
                dp[i][j][k] = 0;
            }
        } 
    }


    int match = 0;
    int value = 0;
    for(int i = 0; i < q; i++){
        for(int j = 1; j < a[i].size() + 1; j++){
            for(int k = 1; k < b[i].size() + 1; k++){
                if(a[i][j - 1] == b[i][k - 1]) match = 1;
                else match = 0;
                value = max({dp[i][j - 1][k - 1] + match, dp[i][j - 1][k], dp[i][j][k - 1]});
                dp[i][j][k] = value;
            }
        } 
    }
    for(int i = 0; i < q; i++){
        cout << dp[i][a[i].size()][b[i].size()] << endl;
    }
    return 0;
}

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

int n, m;
char s[1000], t[1000];
int dp[1001][10001];

int main(void){
    cin >> n;

    for(int i=0;i<n;i++){
        cin >> s;
        cin >> t;
        int sizeofs = strlen(s);
        int sizeoft = strlen(t);
        for(int i=0;i<sizeofs;i++){
            for(int j=0;j<sizeoft;j++){
                if(s[i] == t[j]){
                    dp[i+1][j+1] = dp[i][j] + 1;
                }else{
                    dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
                }
                cout << s[3] << endl;
            }
        }
        cout << dp[sizeofs][sizeoft] <<endl;
    }

    return 0;
}

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

#define NMAX 1000
int lcs[NMAX+1][NMAX+1];

int solveLCS(string S1, string S2) {
	int n1 = S1.size(), n2 = S2.size(), vmax = 0;
	
	for (int i = 0; i <= n1; i++) lcs[i][0] = 0;
	for (int i = 0; i <= n2; i++) lcs[0][i] = 0;

	for (int i = 1; i <= n1; i++) {
		for (int j = 1; j <= n2; j++) {
			if (S1[i - 1] == S2[j - 1]) {
				lcs[i][j] = lcs[i - 1][j - 1] + 1;
			}
			else {
				lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
			}
			vmax = max(vmax, lcs[i][j]);
		}
	}
	return vmax;
}

int main() {
	int N; cin >> N;
	string S1, S2;

	for (int i = 0; i < N; i++) {
		cin >> S1 >> S2;
		cout << solveLCS(S1, S2) << endl;
	}
	return 0;
}

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

using namespace std;

string s, t;

int main() {
	int n;
	cin >> n;
	while (n--) {
		//dp[i][j] := s???i??????????????§???t???j??????????????§?????£?????¨??????LCS
		vector<vector<int>> dp(200, vector<int>(200));
		cin >> s >> t;
		dp[0][0] = (s[0] == t[0]);
		for (int i = 1; i < s.size(); i++)dp[i][0] = (bool)(dp[0][0] + (s[i] == t[0]));
		for (int j = 1; j < t.size(); j++)dp[0][j] = (bool)(dp[0][0] + (s[0] == t[j]));
		
		for (int i = 1; i < s.size(); i++) {
			for (int j = 1; j < t.size(); j++) {
				if (s[i] == t[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[s.size() - 1][t.size() - 1] << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stdlib>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    int Q;
    string X, Y;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        cin >> X >> Y;
        int DP[1001][1001];
        memset(DP, 0, sizeof(DP));
        for (int sx = 1; sx <= X.size(); ++sx) {
            for (int sy = 1; sy <= Y.size(); ++sy) {
                DP[sx][sy] = max(DP[sx][sy-1], DP[sx][sy-1]);
                if (X[sx] == Y[sy]) {
                    DP[sx][sy] = max(DP[sx][sy], DP[sx-1][sy-1]+1);
                }
            }
        }
        cout << DP[X.size()][Y.size()] << endl;
    }
    return 0;
}

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

int C[1001][1001];

int lcs(string X,string Y){
  int m=X.length();
  int n=Y.length();
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
  for (int i=0;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.at(i)==Y.at(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(){
  string s1,s2;
  int n;cin>>n;
  for (int i=0;i<n;i++){
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<endl;
  }
  return 0;
 }

C++: //#if 0
//????????????????§£?????????????????????????????????????????????????????????C++??§string??????????????§???
//?????????????????§???????????§???AOJ?????????????????????Runtime Error??????????????????????????????
//??£????????¨??????????????????????????????????????????????????????Runtime Error???????????¨???????????????
//??§???????????????????????????????????§???
//#endif
#include<iostream>
#include<string>
#define lth 1000

using namespace std;

int main()
{
	int n, L[1010][1010], Lmax = 0, *save;
	string *Xi, *Yi;
	cin >> n;
	save = new int[n];
	if (n <= 20)
	{
		Xi = new string[lth];
		Yi = new string[lth];
	}
	else
	{
		Xi = new string[100];
		Yi = new string[100];
	}
	for (int k = 0; k < n; k++)
	{
		Lmax = 0;
		string X, Y;
		cin >> X >> Y;
		for (int i = 0; i <= X.length(); i++)
		{
			if (i != 0)
				Xi[i] = X.substr(0, i );
		}
		for (int i = 0; i <= Y.length(); i++)
		{
			if (i != 0)
				Yi[i] = Y.substr(0, i );
		}
		for (int i = 0; i <= X.length(); i++)
			for (int j = 0; j <= Y.length(); j++)
			{
				if (i == 0 || j == 0)
					L[i][j] = 0;
				else if (Xi[i][i - 1] == Yi[j][j - 1])
				{
					L[i][j] = L[i - 1][j - 1] + 1;
				}
				else
				{
					L[i][j] = (L[i][j - 1] > L[i - 1][j]?L[i][j - 1] : L[i - 1][j]);
				}
				if (Lmax < L[i][j]) Lmax = L[i][j];
			}
		save[k] = Lmax;
	}

	for (int i = 0; i < n; i++)
		cout << save[i] << endl;
}