Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 1001

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func lcs(x, y string) int {
	var c [N][N]int
	m := len(x)
	n := len(y)
	var maxl int

	x = " " + x
	y = " " + y

	for i := 1; i <= m; i++ {
		for 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
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	var out bytes.Buffer
	for i := 0; i < q; i++ {
		sc.Scan()
		s1 := sc.Text()
		sc.Scan()
		s2 := sc.Text()
		out.WriteString(fmt.Sprintf("%d\n", lcs(s1, s2)))
	}
	return strings.TrimRight(out.String(), "\n")
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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;
    }
}