Go: package main

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

type Position struct {
	X int
	Y int
}

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 {
	return lcs(strX, strY, Position{0, 0}, make(map[Position]int))
}

func lcs(strX string, strY string, position Position, memo map[Position]int) int {
	if position.X >= len(strX) || position.Y >= len(strY) {
		return 0
	}
	if v, ok := memo[position]; ok {
		return v
	}
	if strX[position.X] == strY[position.Y] {
		result := lcs(strX, strY, Position{position.X + 1, position.Y + 1}, memo)
		memo[position] = result + 1
		return memo[position]
	} else {
		result1 := lcs(strX, strY, Position{position.X + 1, position.Y}, memo)
		result2 := lcs(strX, strY, Position{position.X, position.Y + 1}, memo)
		var result int
		if result1 > result2 {
			result = result1
		} else {
			result = result2
		}
		memo[position] = result
		return result
	}
}

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>

using namespace std;

int lcs(string X, string Y) {
  X = ' ' + X;
  Y = ' ' + Y;
  int memo[1010][1010];
  int maxl = 0;

  // 初期化 境界条件を考える必要がなくなる
  for (int i = 0; i < X.size(); i++) memo[i][0] = 0;
  for (int j = 0; j < Y.size(); j++) memo[0][j] = 0;

  for (int i = 1; i < X.size(); i++) {
    for (int j = 1; j < Y.size(); j++) {
      if (X[i] == Y[j]) {
        //cout << "count up!" << endl;
        memo[i][j] = memo[i-1][j-1] + 1;
      } else {
        memo[i][j] = max(memo[i-1][j], memo[i][j-1]);
      }
      maxl = max(maxl, memo[i][j]);
    }
  }
  return maxl;
}

int main() {
  int q; cin >> q;
  for (int i = 0; i < q; i++) {
    string X, Y; cin >> X >> Y;
    cout << lcs(X, Y) << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/2)
#define PI (2*acos(0.0))
#define EPS (1e-8)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

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

int main(void){
  ios_base::sync_with_stdio(0);
  int N;  cin >> N;
  while(N--){
    string a, b;  cin >> a >> b;
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < a.size(); i++){
      for(int j = 0; j < b.size(); j++){
        if(a[i] == b[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[a.size()][b.size()] << endl;
  }
  return 0; 
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	
#include<list>
#include<set>

constexpr auto PI = 3.14159265359;

using namespace std;

int main() {
	int q;
	string x;
	string y;
	cin >> q;

	

	for (int k = 0; k < q; ++k) {
		cin >> x;
		cin >> y;
		x = ' ' + x;
		y = ' ' + y;
		vector<vector<int>> LCS(x.length() + 1, vector<int>(y.length() + 1, 0));

		for (int i = 1; i < x.length(); ++i) {
			for (int j = 1; j < y.length(); ++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]);
				}
			}
		}
		cout << LCS[x.length() - 1][y.length() - 1] << endl;
	}


	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  vector <vector<int> > dp;
  string x,y;
  int n;

  cin >> n;
  for(int times=0;times<n;times++){
    int ans =0;

    cin >> x >> y;
    dp.resize(y.size()+1);
    for(int i=0;i<=y.size();i++){
      dp[i].resize(x.size()+1);
    }

    for(int i=0;i<=y.size();i++){
      dp[i][0]=0;
    }
    for(int i=0;i<=x.size();i++){
      dp[0][i]=0;
    }

    for(int i=1;i<=y.size();i++){
      for(int j=1;j<=x.size();j++){
        if(x[j-1]==y[i-1]){
          dp[i][j] = dp[i-1][j-1]+1;
        }else{
          dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
	ans = max(ans,dp[i][j]);
      }
    }

    cout << ans << endl;
  }
}

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

#define MAX 100

using namespace std;

int lcs(string s1, string s2) {
    int C[MAX+1][MAX+1];
    int m = s1.size();
    int n = s2.size();
    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 (s1[i-1] == s2[j-1]) {
                C[i][j] = C[i-1][j-1] + 1;
            }
            else {
                C[i][j] = max(C[i][j-1], C[i-1][j]);
            }
        }
    }

    return C[m][n];
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        string s1, s2;
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxx = 1010;
int c[maxx][maxx];

int lcs(char s1[],char s2[]) {
	int m = strlen(s1), n = strlen(s2);
	for (int i = 1; i <= m; i++)
		c[i][0] = 0;
	for (int i = 1; i <= n; i++)
		c[0][i] = 0;

	int ans = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (s1[i] == s2[j])
				c[i][j] = c[i - 1][j - 1] + 1;
			else
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			ans = max(ans, c[i][j]);
		}
	}
	return ans;
}
int main()
{
	char s1[maxx], s2[maxx];
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		scanf("%s %s", s1, s2);
		printf("%d\n", lcs(s1, s2));
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;

static const int ra =1000;

int lcs(string A, string B){
  int ca[ra+1][ra+1];
  int mi =A.size();
  int ni = B.size();
  int most = 0;

  A = ' ' + A;
  B = ' '+B;

  for(int i=1;i<=mi;i++){
    ca[i][0]=0;
  }
  for(int j=0;j<=ni;j++){
    ca[0][j] = 0;
  }

  for(int i =1;i<=mi;i++){
    for(int j=1;j<=ni;j++){
      if(A[i] == B[j]){
	ca[i][j] = ca[i-1][j-1]+1;
      }
      else{
	ca[i][j] = max(ca[i-1][j],ca[i][j-1]);
      }
      most = max(most,ca[i][j]);
    }
  }
  return most;
}

int main(){
  string K1,K2;
  int num,i;
  cin >>num ;
  for(i=0;i<num;i++){
    cin >> K1 >> K2;
    cout << lcs(K1,K2) << endl;
  }
  return 0;
}