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>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int q;
	cin >> q;
	REP(k, q) {
		string X, Y;
		cin >> X >> Y;
		int x = X.size(), y = Y.size();
		vector<vector<int>> dp(x + 1, vector<int>(y + 1));
		REP(i, x) {
			REP(j, y) {
				if (X[i] != Y[j]) {
					dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
				} else {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
			}
		}
		cout << dp[x][y] << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll q;
  cin >> q;
  while(q--) {
    string s;
    string t;
    cin >> s >> t;
    mat dp(s.size()+1,vec(t.size()+1));
    for(ll i=0;i<s.size();i++) {
      for(ll j=0;j<t.size();j++) {
        if(s[i]==t[j]) {
          dp[i+1][j+1]=max({dp[i][j]+1,dp[i+1][j],dp[i][j+1]});
        }
        else {
          dp[i+1][j+1]=max({dp[i][j],dp[i+1][j],dp[i][j+1]});
        }
      }
    }
    cout << dp[s.size()][t.size()] << endl;
  }
}

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

int Max(int &a,int b){return a=max(a,b);}

int LCS(string &a,string &b){
  int n = a.size();
  int m = b.size();
  vector <vector<int> > dp(n+1,vector<int>(m+1));

  for(int i=0;i<=n;i++)
    for(int j=0;j<=m;j++){
      if(i<n&&j<m&&a[i] == b[j]) Max(dp[i+1][j+1],dp[i][j]+1);
      Max(dp[i+1][j],dp[i][j]);
      Max(dp[i][j+1],dp[i][j]);
    }
  return dp[n][m];
}

int main(){
  int q;
  cin>>q;
  while(q--){
    string a,b;
    cin>>a>>b;
    cout<<LCS(a,b)<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int lcs(const string& a, const string& b) {
    int dp[1000+1][1000+1];
    int al = a.size();
    int bl = b.size();
    memset(dp, 0, sizeof(dp[0][0])*al*bl);
    for (int i = 1; i <= al; ++i) {
        for (int j = 1; j <= bl; ++j) {
            if(a[i - 1] == b[j - 1]) {
//                cout << "=" << endl;
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
            // cout << a[i] << ":" << b[j] << endl;
            // cout << i << "," << j << "," << dp[i][j] << endl;
            // cout << endl;
        }
    }
    return dp[al][bl];
}

int main() {
    int n;
    scanf("%d", &n);

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

C++: #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(v) v.begin(), v.end()
using namespace std;

string a,b;
int dp[1010][1010];
bool u[1010][1010];

int fn(int i,int j){
    if( i < 0 || j < 0 ) return 0;
    if( u[i][j] ) return dp[i][j];
    u[i][j] = true;
    int ans = max( fn(i-1,j) , fn(i,j-1) );
    if( a[i]==b[j] ) ans = max( ans , 1+fn(i-1,j-1) );
    return dp[i][j] = ans;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    for(int i=1; i<=t; i++){
        cin >> a >> b;
        for(int j=0; j<a.size(); j++) for(int k=0; k<b.size(); k++) u[j][k] = false;
        cout << fn( a.size()-1 , b.size()-1 ) << "\n";
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define REP0(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define REPB0(i,n) for(int i=n-1;i>=0;i--)
#define REPB1(i,n) for(int i=n;i>0;i--)
#define llong long long
#define INF 2000000000
#define NIL -1
#define N 1000
using namespace std;
int LCS(string X,string Y){
  int C[N+1][N+1];
  int m=X.size();
  int n=Y.size();
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
  C[0][0]=0;
  REP1(i,m) C[i][0]=0;
  REP1(i,n) C[0][i]=0;
  REP1(i,m){
    REP1(j,n){
      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(){
  string s1,s2;
  int n;
  scanf("%d",&n);
  REP0(i,n){
    cin>>s1>>s2;
    printf("%d\n",LCS(s1,s2));
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int N=1000;
int lcs(string X,string Y){
    int c[N+1][N+1];
    int m=X.size();
    int n=Y.size();
    int maxl=0;
    for(int i=0;i<n+1;i++) c[0][i]=0;
    for(int i=0;i<m+1;i++) c[i][0]=0;
    for(int i=1;i<m+1;i++){
        for(int j=1;j<n+1;j++){
            if(X[i-1]==Y[j-1]) c[i][j]=c[i-1][j-1]+1;
            else c[i][j]=max(c[i][j-1],c[i-1][j]);
            maxl=max(maxl,c[i][j]);
        }
    }
    return maxl;
}
int main(void){
    int q;
    string X,Y;
    cin >> q;
    for(int i=0;i<q;i++){
        cin >> X >> Y;
        cout << lcs(X,Y) << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<limits.h>
#include<string>
using namespace std;
 
int LCS(string a, string b){
    int m=a.size();
    int n=b.size();
    int T[m+1][n+1];
    int i,j;
    for (i=0;i<m+1;i++) T[i][0]=i;
    for (j=0;j<n+1;j++) T[0][j]=j;
    for (i=1;i<m+1;i++){
        for (j=1;j<n+1;j++){
            int min=T[i-1][j]+1;
            if (min>T[i][j-1]+1){
                min=T[i][j-1]+1;
            }
            if ((a[i-1]==b[j-1])&&(min>T[i-1][j-1]+1)){
                min=T[i-1][j-1]+1;
            }
            T[i][j]=min;
        }
    }
    return m+n-T[m][n];
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m,i;
    cin >> m;
     
    string a,b;
    for (i=0;i<m;i++){
        cin >> a >> b;
        cout << LCS(a,b) << endl;
    }
    return 0;
}