Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		strX := nextText(sc)
		strY := nextText(sc)
		fmt.Println(calcLcs(strX, strY))
	}
}

func calcLcs(strX, strY string) int {
	lenX, lenY := len(strX), len(strY)
	memo := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		memo[i] = make([]int, lenY+1)
	}

	lcs := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if strX[i-1] == strY[j-1] {
				memo[i][j] = memo[i-1][j-1] + 1
			} else {
				if memo[i-1][j] > memo[i][j-1] {
					memo[i][j] = memo[i-1][j]
				} else {
					memo[i][j] = memo[i][j-1]
				}
			}
			if memo[i][j] > lcs {
				lcs = memo[i][j]
			}
		}
	}
	return lcs
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int dp[1001][1001];
string s,t;
int n,m,a,ans;
int main(){
  cin>>a;
  for(int b=0;b<a;b++){
    cin>>s>>t;
    for(int i=0;i<=1000;i++)
      for(int j=0;j<=1000;j++)
    dp[i][j]=0;
    m=s.size();
    n=t.size();
    ans=0;
    for(int i=1;i<=m;i++){
      for(int j=1;j<=n;j++){
    if(s[i-1]==t[j-1]){
      dp[i][j]=dp[i-1][j-1]+1;
    }else{
      dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
      }
    } 
    cout<<dp[m][n]<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#define N 1000

int c[N + 1][N + 1];

int max(int x, int y)
{
	return (x > y) ? x : y;
}

int lcs(std::string X, std::string Y)
{
	int ret = 0;
	int m = X.length();
	int n = Y.length();
	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][j - 1], c[i - 1][j]);
			}
			ret = max(c[i][j], ret);
		}
	}

	return ret;
}

int main()
{
	int n;
	std::cin >> n;

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

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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse

int main(){
    int N;
    cin>>N;
    rep(c,N){
        string A,B;
        cin>>A>>B;
        int a=A.length();
        int b=B.length();
        vector<vector<int> >dp(a+1,vector<int>(b+1,0));

        //i,j時点での最長文字列を格納する
        //一致した文字があればそこでインクリメントする。(iの時)
        //以前に共通文字列がカウントされていればそれに合わさる形となる。前後関係も正しい(i+1の時)

        rep(i,a){
            rep(j,b){
                if(A[i]==B[j])dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1]);
                dp[i+1][j+1]=max(dp[i+1][j],dp[i+1][j+1]);
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
            }
        }
        cout<<dp[a][b]<<endl;
    }

    return 0;
}

//a=97,z=122

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


int main(int argc, char *argv[]){
  int n;
  cin >> n;
  for (int r = 0; r < n; r++) {

    string x, y;
    cin >> x >> y;
    string dp[y.length() + 1][x.length() + 1];

    for (int i = 0; i < y.length(); i++) {
      for (int j = 0; j < x.length(); j++) {
        if(y[i] == x[j]){
          dp[i + 1][j + 1] = dp[i][j] + y[i];
        }else{
          dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        }
      }
    }
    std::cout << dp[y.length()][x.length()].length() << std::endl;
  }
  return 0;
}