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;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

int main()
{
    cin >> n;
    ll ma = 0;
    REP(i, n)
    {
        string t;
        cin >> s >> t;
        ll c[100][100] = { 0 };
        ma = 0;
        s = ' ' + s; //????????????????????????
        t = ' ' + t;
        FOR(i, 1, s.size())
        {
            c[i][0] = 0;
        }
        FOR(i, 1, t.size())
        {
            c[0][i] = 0;
        }
        FOR(i, 1, s.size())
        {
            FOR(j, 1, t.size())
            {
                if (s[i] == t[j]) {
                    c[i][j] = c[i - 1][j - 1] + 1;
                } else {
                    c[i][j] = max(c[i - 1][j], c[i][j - 1]);
                }
                ma = max(ma, c[i][j]);
            }
        }
        cout << ma << Endl;
    }
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int dp[1001][1001];
int q;

void solve(){
  char x[1001],y[1001];
  scanf("%s %s",x,y);
  int lx = strlen(x);
  int ly = strlen(y);
  for(int i=0;i<=lx;i++){
    for(int j=0;j<=ly;j++){
      if(i==0||j==0) dp[i][j] = 0;
      else if(x[i]==y[j]) dp[i][j] = dp[i-1][j-1]+1;
      else dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
    }
  }
  printf("%d\n",dp[lx][ly]);
  return;
}


int main(){
  scanf("%d",&q);
  for(int i=0;i<q;i++) solve();
  return 0;
}

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

int main(void){
  int q;
  cin >> q;

  for(int i=0; i<q; i++){
    string x, y;
    cin >> x >> y;
    
    int nx, ny;
    nx = x.size();
    ny = y.size();
    
    vector< vector<int> > lcs(nx+1, vector<int>(ny+1, 0));

    for(int i=1; i<=nx; i++)
      for(int j=1; j<=ny; j++){
	if(x[i] == y[j])
	  lcs[i][j] = lcs[i-1][j-1] + 1;
	else
	  lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
      }
    
    cout << lcs[nx][ny] << endl;
  }

  return 0;
}

C++: //最長共通部分列
//要は何枚のコインで支払えますか問題。

// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000019
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int dp[2000][2000];
vector<int> w(2000);
vector<int> v(2000);

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    //double mini=INF;
    int maxi=0,f=0,sum=0;
    int i;
    double h;
    int n,x,m;
    int a,b,d,c;
    //int e,weight;
    int target;
    //targetが目的値、nが個数
    cin>>n;

    rep(_,n){
        string str1,str2;
        cin>>str1>>str2;

        //DPテーブルを0で初期化
        for(ll i=0;i<str1.length()+1;i++){
            for(ll j=0;j<str2.length()+2;j++){
                dp[i][j]=0;
            }
        }
        rep(i,str1.length()){
            rep(j,str2.length()){
                if(str1[i]==str2[j]){
                    dp[i+1][j+1]=dp[i][j]+1;
                }else{
                    dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
                }
            }
        }
        cout<<dp[str1.length()][str2.length()]<<endl;;
    }


    //dpテーブルのこたえにあたる部分を出力
    //今回は配るDPなのでn番目を出力しているところに注意!
    //cout<<dp[n][target]<<endl;


    return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int p[1001][1001]={0};
int main(){
  int i,j,q,e,l,z,m,u,n;
  char x[2001],y[2001];
  cin>>q;
  for(e=0;e<q;e++){
    scanf("%s %s",x,y);
    l=strlen(x);
    z=strlen(y);
 
    for(i=0;i<=l;i++){
      for(j=0;j<=z;j++){
        p[i][j]=0;
      }
    }
    for(i=1;i<=z;i++){
      for(j=1;j<=l;j++){
        if(y[i-1]==x[j-1])p[j][i]=p[j-1][i-1]+1;
        else p[j][i]=max(p[j-1][i],p[j][i-1]);
      }
    }
    cout<<p[l][z]<<endl;
  }
  return 0;
}

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 s = S.size(), t = T.size();
		int dp[1010][1010] = { 0 };
		for (int i = 0; i < s; i++) {
			for (int j = 0; j < t; j++) {
				if (S[i] == T[j]) {
					dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
				}
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
			}
		}
		cout << dp[s][t] << endl;
	}
}

C++: #include<iostream>
using namespace std;
int lcs(string a,string b)
{
    if(a.length()<=0||b.length()<=0)
    {
        return 0;
    }
    else if(a[a.length()-1]==b[b.length()-1])
    {
        return 1+lcs(a.substr(0,a.length()-1),b.substr(0,b.length()-1));
    }
    else
    {
        return max(lcs(a.substr(0,a.length()),b.substr(0,b.length()-1)),lcs(a.substr(0,a.length()-1),b.substr(0,b.length())));
    }
};
int main()
{
    int num;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        string a,b;
        cin>>a>>b;
        cout<<lcs(a,b)<<endl;
    }
}

C++: #include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string x,y;
    cin >> x >> y;

    int m,n;
    m = x.length();
    n = y.length();

    vector< vector<int> > mat(m+1, vector<int>(n+1,0));

    for (int sum = 2; sum <= m+n; sum++) {
      for (int j = 1; j < sum; j++) {
        int k = sum - j;
        if (k <= 0 || k > n || j > m) continue;

        int plus = x[j-1] == y[k-1] ? 1 : 0;
        mat[j][k] = max(max(mat[j-1][k], mat[j][k-1]), mat[j-1][k-1] + plus);
      }
    }

    cout << mat[m][n] << eol;
  }
  
  return 0;
}