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;

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;
  
  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[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 <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef double db;
typedef string str;
// head

void solve(){
    str s,t;
    cin>>s>>t;
    int S=s.size();
    int T=t.size();
    int dp[1010][1010];
    range(i,S){
        range(j,T){
            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[S][T]<<endl;
}

int main(){
    int n;
    cin>>n;
    range(i,n)
    solve();
}

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

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

// 最長共通部分列 ... len(s) == m, len(t) == n とすると, O(mn)
int lcs(std::string s, std::string t) {
  std::vector<std::vector<int> > dp(s.size() + 1, std::vector<int>(t.size() + 1, 0));

  for (int i = 0; i < s.size(); ++i) {
    for (int j = 0; j < t.size(); ++j) {
      if (s[i] == t[j]) {
        dp[i][j] = (i == 0 ? (j == 0 ? 1 : 0) : 0);
      }
      else if (i >= 0 && j >= 0 && dp[i - 1][j] >= dp[j][i - 1]) {
        dp[i][j] = dp[i - 1][j];
      }
      else if (i >= 0 && j >= 0) {
        dp[i][j] = dp[i][j - 1];
      }
    }
  }

  return dp[s.size()][t.size()];
}

int main() {
  int q;
  std::string s, t;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> s >> t;
    cout << lcs(s, t) << endl;
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main() {
    int num; cin >> num;
    rep(k,0,num) {
        string s1,s2;
        cin >> s1 >> s2;

        int dp[101][101]; //s1???i??????????????§???s2???j??????????????§??§???LCS????±???????????????????
        int n = s1.length();
        int m = s2.length();
        rep(i,0,m+1) dp[0][i] = 0;

        rep(i,0,n) {
            rep(j,0,m) {
                if(s1[i]==s2[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 <algorithm>
using namespace std;

#define MAX 1000

int lcs(string X, string Y) {
    int c[MAX+1][MAX+1];
    int m = X.size();
    int n = Y.size();
    int i, j;
    int maxlen = 0;
    X = " " + X;
    Y = " " + Y;

    for (i = 1 ; 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 if( c[i-1][j] >= c[i][j-1] ) {
                c[i][j] = c[i-1][j];
            }else {
                c[i][j] = c[i][j-1];
            }
            maxlen = max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}

int main (void) {
    int N, i;
    string x, y;
    

    cin >> N;

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

    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
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;
    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[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 <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
#include <inttypes.h>
int c[1001][1001] = {0};
int LCS(std::string s, std::string t){
    int n, m;
    n = s.size();
    m = t.size();
    int maxlen = 0;
    for(int i = 1; i <= n; i++){
        c[i][0] = 0;
    }
    for(int i = 1; i <= m; i++){
        c[0][i] = 0;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i - 1] == t[j - 1]){
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else{
                c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
            }
            maxlen = std::max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}
int main(){
    int N;

    std::cin >> N;
    std::string s1, s2;
    for(int i = 0; i<N; i++){
        std::cin >> s1 >> s2;
       
        std::cout << LCS(s1,s2) << std::endl;
    }
    return 0;
}