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 a,string b)
{
    if(a.length()<=0||b.length()<=0)
    {
        return 0;
    }
    else if(a[a.length()-1]==b[b.length()-1])
    {
        return 1+lcs(a.substr(0,a.length()-1),b.substr(0,b.length()-1));
    }
    else
    {
        return max(lcs(a.substr(0,a.length()),b.substr(0,b.length()-1)),lcs(a.substr(0,a.length()-1),b.substr(0,b.length())));
    }
};
int main()
{
    int num;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        string a,b;
        cin>>a>>b;
        cout<<lcs(a,b)<<endl;
    }
}

C++: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    *t++;
    while(t != V.end()) {
        cout << " " << *t++;
        // if(t != V.end()) cout << " ";
    }
    cout << endl;
};
vector<vector<int>> dp(1001, vector<int>(1001));

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q;
    string S, T;
    cin >> Q;
    rep(q, Q) {
        cin >> S >> T;
        dp.assign(S.size() + 1, vector<int>(T.size() + 1, 0));
        rep(i, 0, S.size()) {
            rep(j, 0, T.size()) {
                if(S.at(i) == T.at(j)) {
                    dp.at(i + 1).at(j + 1) = dp.at(i).at(j) + 1;
                } else {
                    dp.at(i + 1).at(j + 1) =
                        max(dp.at(i + 1).at(j), dp.at(i).at(j + 1));
                }
            }
        }
        cout << dp.at(S.size()).at(T.size()) << endl;
    }
}

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

static const int N = 1000;

int lcs(string X, string Y){
  int c[N+1][N+1];
  int m = X.size(), 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(){
    ios::sync_with_stdio(false);
    string s1, s2;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
      cin >> s1 >> s2;
      cout << lcs(s1, s2) << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
int dp[1000+1][1000+1];
int lim;
//int cost_vec[/*num*/];
//int val_vec[/*num*/];
int main() {
	int num;
	cin >> num;
	vector<string> vec(2*num);
	REP(i, num) {
		cin >> vec[2 * i];
		cin >> vec[2 * i + 1];
	}
	REP(i, num) {
		memset(dp, 0, sizeof(dp));
		REP(k, vec[i * 2].size()) {
			REP(n, vec[i * 2+1].size()) {
				if (vec[i * 2][k] == vec[i * 2 + 1][n]) {
					dp[k + 1][n + 1] = dp[k][n] + 1;
				}
				else {
					dp[k + 1][n + 1] = max(dp[k][n + 1], dp[k + 1][n]);
				}
			}
		}
		cout << dp[vec[i * 2].size()][vec[i * 2+1].size()] << endl;
	}
	return 0;
}

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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int q; cin >> q;
    REP(i, q)
    {
        string a, b; cin >> a >> b;
        vvi dp(a.length()+1, vi(b.length()+1));
        REP(j, a.length())
        {
            REP(k, b.length())
            {
                if(a[j] == b[k]) dp[j+1][k+1] = dp[j][k]+1;
                chmax(dp[j+1][k+1], dp[j][k+1]);
                chmax(dp[j+1][k+1], dp[j+1][k]);
            }
        }
        cout << dp[a.length()][b.length()] << endl;
    }
}

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

int table[150][150];
int l1, l2;

int checkLCS(string s1, string s2){
	table[150][150] = {};
	

	for (int i = 1; i <= l1 - 1;i++) {
		for (int j = 1; j <= l2 - 1;j++) {
			table[i][j] = max(max(table[i-1][j],table[i][j-1]), (s1[i]==s2[j])+table[i-1][j-1]);
		}
	}


	return table[l1-1][l2-1] + 1;
	
}



int main(void) {
	
	int q;
	string s1, s2;

	cin >> q;

	for (int i = 0;i <= q - 1;i++) {
		cin >> s1 >> s2;
		l1 = s1.length();
		l2 = s2.length();

		cout << checkLCS(s1, s2) << endl;
	}

	return 0;
}