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>
#include <string>
#include <algorithm>
using namespace std;

int main(){
  int number;
  string x;
  string y;
  int L[100][100];
  cin >> number;
  while(cin >> x >> y){
    for(int i = 0; i <= x.length(); i++){
      for(int j = 0; j <= y.length(); j++){
	if(i <= 0 || j <= 0)
	  L[i][j] = 0;
	else if(x[i-1] == y[j-1])
	  L[i][j] = 1 + L[i-1][j-1];
	else
	  L[i][j] = max(L[i][j-1], L[i-1][j]);
      }
    }
    cout << L[x.length()][y.length()] << endl;
  }
}

#if 0
 else?????¨?????????"L[i][j] ="????????????????????¨???????\????????????????????????????????????§30??????????§?????????????
 ????????????????????§????????¬??§?????????????????????(??????????????£?????????)??? AOJ??§???RuntimeError????????£???????????????
 ??????????????°????????§RuntimeError????????????????????????????????¨???????????§???????????????
 #endif

C++: /*
 * Problem Description: Longest Common Subsequence
 * Category: Dynamic Programming
 * Author: Khan
 * Date: 18th October, 2017
 */

#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 maxLength = 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]);
            maxLength = max(maxLength, c[i][j]);
        }
    }
    return maxLength;
}

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    string x, y;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define vi vector<int>
#define vl vector<long long>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define MOD 1e9+7

template<class T> bool chmax(T &a, const T & b) {
    if (a<b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a, const T & b) {
    if (a>b) {
        a = b;
        return true;
    }
    return false;
}

const int MAX_N = 1010;
int dp[MAX_N][MAX_N];
string X, Y;
//dp[i+1][j+1]:Xのi文字目とYのj文字目までのLCS
void LCS(int n, int m) {
    dp[0][0] = 0;
    REP(i, n) {
        REP(j, m) {
            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]);
            }
        }
    }
}

int main() {
    int q;
    cin >> q;
    REP(j, q) {
        cin >> X >> Y;
        int n = X.length();
        int m = Y.length();
        LCS(n, m);
        cout << dp[n][m] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int q;
    cin >> q;
    while (q--)
    {
        string s, t;
        cin >> s >> t;
        int n = s.size();
        int m = t.size();
        vector<vector<ll>> dp(n + 10, vector<ll>(m + 10, 0));
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if (s[i - 1] == t[j - 1])
                {
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
                }
                else
                {
                    dp[i][j] = max({dp[i][j], dp[i - 1][j], dp[i][j - 1]});
                }
            }
        }
        // debug_vec2(dp);
        cout << dp[n][m] << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";}
using namespace std;
using ll = long long;

int dp[1005][1005];
vector<int> ans;

int main(void) {
    int q;
    cin >> q;
    rep (_, q) {
        string s, t;
        cin >> s >> t;

        rep (i, 1002) rep (j, 1002) dp[i][j] = 0;


        for (int si = 1; si <= s.size(); si++) {
            for (int ti = 1; ti <= t.size(); ti++) {
                if (s[si - 1] == t[ti - 1]) {
                    dp[si][ti] = dp[si - 1][ti - 1] + 1;
                }
                else {
                    dp[si][ti] = max(dp[si - 1][ti], dp[si][ti - 1]);
                }
            }
        }
        ans.push_back(dp[s.size()][t.size()]);
    }
    
    rep (i, q) cout << ans[i] << endl;
    return 0;
}