Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

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

using namespace std;

const int MAX = 1000;
int ary[MAX][MAX];

int getVal(int n, int m) {

	if (m >= 0 && n >= 0 && m < MAX && n < MAX) {
		return ary[n][m];
	}
	else {
		return 0;
	}
}

int LCS(string s1, string s2) {

	int m, n;
	m = s1.length();
	n = s2.length();
	const char* c1 = s1.c_str();
	const char* c2 = s2.c_str();

	for (int i = 0;i < n;i++) {
		for (int k = 0;k < m;k++) {

			if (c1[k] != c2[i]) {
				ary[i][k] = max(getVal(i - 1, k), getVal(i, k - 1));
			}
			else if (c1[k] == c2[i]) {
				ary[i][k] = getVal(i - 1, k- 1) + 1;
			}
		}
	}

	return ary[n - 1][m - 1];
}


int main() {


	int num;
	cin >> num;

	string str1, str2;

	for (int i = 0;i < num;i++) {
		cin >> str1 >> str2;

		cout << LCS(str1, str2) << 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;//??¨X[0]????????\?????????
	Y=' '+Y;//??¨Y[0]????????\?????????
	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++: #include <iostream>
#include <string>
#include <vector>


constexpr int MAXLENGTH = 1000;
int C[MAXLENGTH + 1][MAXLENGTH + 1];
int lcs(std::string lhs, std::string rhs) {
    int lnum = lhs.length();
    int rnum = rhs.length();
    for (int i = 0; i <= lnum; i++) {
        C[i][0] = 0;
    }
    for (int i = 0; i <= rnum; i++) {
        C[0][i] = 0;
    }
    for (int il = 1; il <= lnum; il++) {
        for (int ir = 1; ir <= rnum; ir++) {
            if (lhs[il-1] == rhs[ir-1]) {
                C[il][ir] = C[il - 1][ir - 1] + 1;
            }else if(C[il - 1][ir] >= C[il][ir - 1]) {
                C[il][ir] = C[il-1][ir];
            }else{
                C[il][ir] = C[il][ir - 1];
            }
        }
    }
    return C[lnum][rnum];
}

int main() {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::string l, r;
        std::cin >> l;
        std::cin >> r;
        std::cout << lcs(l, r) << std::endl;
    }
}

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 LCS(std::string s,std::string t){
    int n,m,c[1001][1001]={0};
    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]==t[j]){
                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(c[i][j],maxlen);
        }
    }
    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;
}

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

const int s=1001;

using namespace std;

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

	int q;
	static unsigned int dp[s][s] = {0};
	
	dp[0][0] = 0; dp[0][1] = 0; dp[1][0] = 0;

	cin >> q;
	for(int k=0; k < q; k++){
		string X,Y;
		cin >> X >> Y;
		int i,j;
		for(i=0;i<X.size();i++){
			for(j=0;j<Y.size();j++){
				if(X[i] == Y[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[i][j] << "\n";
	}
	return 0;
}

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

using namespace std;

/**
 *  lcs(m,n) = 
 *  if x[m] == y[n] lcs[m-1,n-1]+1
 *  max(lcs[m-1,n],lcs[m,n-1])
 *
 */

string x, y;

const int q = 150;

int c[q][q];

int lcs(int m, int n)
{
	if (m == -1 || n== -1) return 0;
	if (x[m] == y[n]) return lcs(m-1,n-1) + 1;
	int & cc = c[m][n];
	if (cc != -1) return cc;
	int xx = lcs(m-1,n);
	int yy = lcs(m,n-1);
	cc = xx > yy ? xx : yy;
	return cc;
}

int main()
{
	int n = 0;
	x.resize(q);
	y.resize(q);
	memset(c, -1, sizeof(c));
	cin >> n; 
	for (int i=0;i<n;i++)
	{
		cin >> x;
		cin >> y;
		cout << lcs(x.size()-1, y.size()-1) << endl;
		x.clear();
		y.clear();
	}
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};


int main(int argc, char const *argv[]) {
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		string s1;
		string s2;
		cin >> s1 >> s2;
		int dp[1000][1000] = {{0}};
		for (int i = 0; i < s1.size(); ++i) {
			if (s1[i] == s2[0]) {
				dp[i][0] = 1;
			}
		}
		for (int i = 0; i < s2.size(); ++i) {
			if (s1[0] == s2[i]) {
				dp[0][i] = 1;
			}
		}
		for (int i = 1; i < s1.size(); ++i) {
			for (int j = 1; j < s2.size(); ++j) {
				if (s1[i] == s2[j]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				} else {
					dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
				}
			}
		}
		cout << dp[s1.size() - 1][s2.size() - 1] << endl;
	}	

	return 0;
}