Go: package main

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

const max int = 1000 + 1
var A [][]int

func lcs(x, y string) int {
	x = " " + x
	y = " " + y
	for i:=0;i<len(x); i++ {
		for j:=0;j<len(y); j++ {
			A[i][j] = 0
		}
	}
	for i:=1; i<len(x); i++ {
		for j:=1; j<len(y); j++ {
			if x[i] == y[j] {
				A[i][j] = A[i-1][j-1] + 1
			} else if A[i-1][j] > A[i][j-1] {
				A[i][j] = A[i-1][j]
			} else {
				A[i][j] = A[i][j-1]
			}
		}
	}
	return A[len(x)-1][len(y)-1]
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num 
}

func nextStr(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}


func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	A = make([][]int, max)
	for i := range A {
		A[i] = make([]int, max)
	}
	n := nextInt(scanner)
	for i:=0; i<n; i++ {
		x := nextStr(scanner)
		y := nextStr(scanner)
		fmt.Printf("%d\n", lcs(x, y))
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define frep(i, m, n) for(int i = m;i < n;i++)
#define frepr(i, m, n) for(int i = m;i >= n;i--)
#define vsort(v) sort(v.begin(),v.end())
#define ll long long
#define inf 999999999
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vst;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
    int q;
    cin >> q;
    rep(p,q){
       string x,y;
       cin >> x >> y;
       vvi dp(x.length(),vi(y.length(),inf));
       rep(i,x.length()){
           rep(j,y.length()){
               if(i==0&&j==0)dp[i][j]=(x[i]==y[j]);
               else if(i==0)dp[i][j]=max(dp[i][j-1],(int)(x[i]==y[j]));
               else if(j==0)dp[i][j]=max((int)(x[i]==y[j]),dp[i-1][j]);
               else if(x[i]==y[j])dp[i][j]=1+dp[i-1][j-1];
               else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
            //    cout << dp[i][j];
           }
        //    cout << endl;
       }
       cout << dp[x.length()-1][y.length()-1] << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
  string  a,b;
  long n=0,i,c=0;
  cin>>a>>b;
  for(i=0;i<a.size();i++)if(a[i]==b[c])if(++n)c++;
  cout<<n<<endl;}
}

C++: #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 maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 0; 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[i]) {
        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() {
  string s1, s2;
  int n;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }

  return 0;
}

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

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

int main()
{
	string s1, s2;
	int q;
	cin >> q;
	while (q--)
	{
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int LCS[1000][1000];

void solve(string x, string y)
{
	static const int offset[3][2] = { {0,0},{1,0},{0,1} };
	for (int i = 1; i != (max(x.size(), y.size())) + 1; i++)
	{
		for (int k = 0; k < 3; k++)
		{
			int xi = min(x.size() - 1, i - 1 + offset[k][0]);
			int yi = min(y.size() - 1, i - 1 + offset[k][1]);
			if (x[xi] == y[yi])
			{
				LCS[xi + 1][yi + 1] = LCS[xi][yi] + 1;
			}
			else
			{
				LCS[xi + 1][yi + 1] = max(LCS[xi][yi + 1], LCS[xi + 1][yi]);
			}
		}
	}

	cout << LCS[x.size()][y.size()] << endl;
}

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

	for (int i = 0; i < 1000; i++)
	{
		LCS[0][i] = 0;
		LCS[i][0] = 0;
	}

	for (int i = 0; i < q; i++)
	{
		string x, y;
		cin >> x >> y;
		solve(x, y);
	}
	return 0;
}