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;

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }


int lcs(string s, string t) { // 最長共通部分列長
  int n = s.size();
  int m = t.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(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+1][j]);
      dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
    }
  }
  return dp[n][m];
}


int main(){
    int n;
    cin >> n;
    rep(i,n) {
        string s, t;
        cin >> s >> t;
        int ans = lcs(s,t);
        cout << ans << endl;
    }
}

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

using namespace std;

int dp[1010][1010];

int main() {
    int q;  cin >> q;
    int *ans = new int[q];
    string s, t;
    int ls, lt, i, j;
    for (int k = 0; k < q; k++) {
        cin >> s >> t;
        ls = s.size(), lt = t.size();

        for (i = 0; i <= ls; i++) {
            for (j = 0; j <= lt; j++)
                dp[i][j] = 0;
        }

        for (i = 0; i < ls; i++) {
            for (j = 0; j <= lt; j++) {
                if (s[i] == t[j])
                    dp[i+1][j+1] = max(dp[i][j]+1, max(dp[i+1][j], dp[i][j+1]));
                else
                    dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }   
        ans[k] = dp[ls][lt];
    }
    for (int k = 0; k < q; k++)
        cout << ans[k] << endl;
    return 0;
}

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

using namespace std;

#define 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;
  X = ' ' + X;
  Y = ' ' + Y;
  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(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;
  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }


  return 0;
}

C++: # include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

int lcs(string x, string y) {
	int c[1200][1200];
	int m = x.size();
	int n = y.size();
	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;
	c[0][0] = 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]);
			}
		}
	}
	return c[m][n];
}

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

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;


int main()
{
	int N;
	cin >> N;
	rep(ii,N)
	{
	string s,t;
	cin >> s >> t;
	int n=s.size(),m=t.size();
	vector<vector<int>> dp(n+1,vector<int>(m+1,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;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<<dp[n][m]<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    vector< vector<int> > dp(1001,vector<int>(1001));
    int q;
    cin >> q;
    
    for(int i=0; i<q; i++){
        string x;
        string y;
        cin >> x;
        cin >> y;
        int xLength = x.length();
        int yLength = y.length();

        for(int j=0; j<xLength; j++){
            for(int k=0; k< yLength; k++){
                int suggest[3];
                if(x[j] == y[k]){
                    dp[j+1][k+1] = dp[j][k] + 1; 
                }else{
                    if(dp[j+1][k] > dp[j][k+1]){
                        dp[j+1][k+1] = dp[j+1][k]; 
                    }else{
                        dp[j+1][k+1] = dp[j][k+1];
                    }
                }
            }
        }
        cout << dp[xLength][yLength] << endl;
    }
    return 0;
}

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

class TLcsSolver
{
    typedef std::vector<std::vector<int> > TTable;
    TTable FTable;
    std::string FArray1;
    std::string FArray2;

    int Count(int i, int j)
    {
        if(i == 0 || j == 0) return 0;
        if(FArray1[i-1] == FArray2[j-1]){
            return FTable[i-1][j-1] + 1;
        }
        return std::max(FTable[i-1][j], FTable[i][j-1]);
    }
    void Solve()
    {
        for(std::size_t i = 1; i < FTable.size(); ++i){
            for(std::size_t j = 1; j < FTable[i].size(); ++j){
                FTable[i][j] = Count(i, j);
            }
        }
    }
public:
    TLcsSolver(const std::string& a, const std::string& b)
     : FArray1(a), FArray2(b)
     , FTable(a.size()+1, std::vector<int>(b.size()+1, 0))
    {
        Solve();
    }
    int Answer()const
    {
        return FTable[FArray1.size()][FArray2.size()];
    }
};

int main()
{
    int n;
    std::scanf("%d", &n);
    char a[1000];
    char b[1000];
    for(int i = 0; i < n; ++i){
        std::fgets(a, 1000, stdin);
        std::fgets(b, 1000, stdin);
        std::printf("%d", TLcsSolver(a, b).Answer());
    }
    return 0;
}