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 <cstring>
#include <string>

using namespace std;


using ll = long long;


ll c[1001][1001];
void solve()
{
    string X, Y;
    cin >> X >> Y;

    memset(c, 0, sizeof(c));
    for (ll i = 0; i <= X.length(); i++)
        c[i][0] = 0;
    for (ll i = 0; i <= Y.length(); i++)
        c[0][i] = 0;

    for (ll i = 1; i <= X.length(); i++) {
        for (ll j = 1; j <= Y.length(); j++) {
            if (X[i - 1] == Y[j - 1]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
        }
    }

    cout << c[X.length()][Y.length()] << endl;
}


int main()
{
    ll q;
    ll c[151][151];

    cin >> q;
    for (ll i = 0; i < q; i++) {
        solve();
    }
}

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

const int length = 1005;
int dp[length][length];

void LCS(std::string X, std::string Y)
{
  auto m = X.length();
  auto n = Y.length();


  for (int i=0; i<m; ++i)
    dp[i][0] = 0;
  for (int j=1; j<n; ++j)
    dp[0][j] = 0;

  for (int i=1; i<=m; ++i)
    {
      for (int j=1; j<=n; ++j)
        {
          if (X[i-1] == Y[j-1])
            dp[i][j] = dp[i-1][j-1] + 1;
          else
            {
              dp[i][j] = std::max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
}

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

  std::string X, Y;
  for (int i=0; i<q; ++i)
    {
      std::cin >> X >> Y;
      LCS(X, Y);
      std::cout << dp[X.length()][Y.length()] << std::endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int NN;
string s1, s2;
int dp[1001][1001];

int run(){
	int N1 = s1.length();
	int N2 = s2.length();
	
	rep(i1, N1+1)
	rep(i2, N2+1){
		if(i1 == 0 || i2 == 0) dp[i1][i2] = 0;
		else{
			if(s1[i1-1] == s2[i2-1]) dp[i1][i2] = dp[i1-1][i2-1] + 1;
			else dp[i1][i2] = max(dp[i1-1][i2], dp[i1][i2-2]);
		}
	}
	return dp[N1][N2];
}

int main() {
	cin >> NN;
	rep(i, NN){
		cin >> s1;
		cin >> s2;
		cout << run() << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;


int lcs(string x, string y){
    int m = x.size();
    int n = y.size();
    int c[m+1][n+1];
    x = ' ' + x;
    y = ' ' + y;
    int maxv = 0;
    rep(i, m+1) c[i][0] = 0;
    for(int i = 1; i<=n; i++) c[0][i] = 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]);
            maxv = max(maxv, c[i][j]);
        }
    }
    return c[m][n];
}

int main(){
    int n, ans;
    cin >> n;
    rep(i, n){
        string x, y;
        cin >> x >> y;
        ans = lcs(x, y);
        cout << ans << endl;
    }
}