Go: package main

import "fmt"

func main() {
	var nPairs int
	fmt.Scanln(&nPairs)

	var a, b string
	for i := 0; i < nPairs; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Println(lcsSize(a, b))
	}
}

func lcsSize(sa, sb string) int {
	dp := make([][]int, len(sa)+1)
	for i := 0; i <= len(sa); i++ {
		dp[i] = make([]int, len(sb)+1)
	}

	for a := 1; a <= len(sa); a++ {
		for b := 1; b <= len(sb); b++ {
			if sa[a-1] == sb[b-1] {
				dp[a][b] = dp[a-1][b-1] + 1
			} else {
				dp[a][b] = max(dp[a][b-1], dp[a-1][b])
			}
		}
	}

	return dp[len(sa)][len(sb)]
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

C++: #include<iostream>
#include<string>
#include<algoritm>
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 = 1;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++: //
#if 0

#endif // 0
#include<iostream>
#define MAX 1010
using namespace std;
int l[MAX][MAX];

int main()
{
    int num;
    cin>>num;       // int l[MAX][MAX];

    for(int i=0;i<num;i++)
    {
        string s1,s2;
        cin>>s1>>s2;
        //int l[MAX][MAX];
        for(int m=0;m<=s1.size();m++)
            for(int n=0;n<=s2.size();n++)
            {
                if(m<=0||n<=0)
                    l[m][n]=0;
                else if(s1[m-1]==s2[n-1])
                    l[m][n]=l[m-1][n-1]+1;
                else
                    l[m][n]=max(l[m][n-1],l[m-1][n]);
            }
        cout<<l[s1.size()][s2.size()]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int dp[1010][1010];

int main(){
  int q;
  cin >> q;
  for(int i = 0; i < q; ++i){
    string x, y;
    cin >> x >> y;
    fill((int*)dp, (int*)dp + sizeof(dp) / sizeof(int), 0);
    // fill((int*)dp, (int*)(dp + 1010), 0);

    int xs = x.size();
    int ys = y.size();

    for(int i = 0; i < xs; ++i){
      for(int j = 0; j < ys; ++j){
        if(x[i] == y[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[xs][ys] << endl;
  }

  return 0;
}

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

std::string x,y;
int lcs[1000][1000] = {0};

int max(int k,int l){
  if(k>l){
    return k;
  }else{
    return l;
  }
}

void LCS(int i,int 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]);
  }
}

void pre(){
  for(int i=0;i<(int)y.size();i++){
    if(x[0] == y[i]){
      lcs[0][i] = 1;
    }else{
      lcs[0][i] = 0;
    }
  }
  for(int i=0;i<(int)x.size();i++){
    if(x[i] == y[0]){
      lcs[i][0] = 1;
    }else{
      lcs[i][0] = 0;
    }
  }
}

int main(){
  int q;
  std::cin >> q;
  for(int k=0;k<q;k++){
    std::cin >> x;
    std::cin >> y;
    int size_x=x.size(),size_y=y.size();
    pre();
    for(int i=1;i<size_x;i++){
      for(int j=1;j<size_y;j++){
	LCS(i,j);
      }
    }

    /*for(int i=0;i<size_x;i++){
      for(int j=0;j<size_y;j++){
	std::cout << lcs[i][j] << ' ';
      }
      std::cout << '\n';
    }
    */
    std::cout << lcs[size_x-1][size_y-1] << '\n'; 

  }
  return 0;
}

C++: #include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int LCS(string s1, string s2){
    int c[s1.size()+1][s2.size()+1];
    rep(i,s1.size()+1) rep(j, s2.size()+1) c[i][j] = 0;
    for(int i=1; i<=s1.size(); i++){
        for(int j=1; j<=s2.size(); j++){
            if(s1[i-1] == s2[j-1]){
                c[i][j] = c[i-1][j-1] + 1;
            }else{
                c[i][j] = max(c[i-1][j], c[i][j-1]);
            }
        }
    }
    return c[s1.size()][s2.size()];
}

int main()
{
    int q; cin >> q;
    rep(i,q){
        string s1, s2;
        cin >> s1 >> s2;
        cout << LCS(s1, s2) << endl;
    }
}

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

int main(){
    int Q;
    cin >> Q;
    rep(k, Q){
        string X, Y;
        cin >> X >> Y;
        X = ' ' + X;
        Y = ' ' + Y;

        vector< vector<int> > A(X.size(), vector<int>(Y.size(), 0));
        for(int i = 1; i < X.size(); i++){
            for(int j = 1; j < Y.size(); j++){                
                if(X[i] == Y[j]){
                    A[i][j] = A[i-1][j-1] + 1;
                } else {
                    A[i][j] = max(A[i-1][j], A[i][j-1]);
                }
            }
        }
        cout << A[X.size() - 1][Y.size() - 1] << endl;
    }
}

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();

    X = ' ' + X;
    Y = ' ' + Y;

    int maxl = 0;

    // Initialize
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 0; 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 <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;
    }