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 <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

int q;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> q;
  rep(i, q) {
    string x, y;
    cin >> x >> y;
    int dp[y.size() + 1][x.size() + 1];
    rep(j, y.size() + 1) {
      fill(dp[j], dp[j] + x.size() + 1, INF);
      dp[j][0] = 0;
    }
    fill(dp[0], dp[0] + x.size() + 1, 0);

    for (int j = 1; j <= y.size(); j++) {
      for (int k = 1; k <= x.size(); k++) {
        if (y[j - 1] == x[k - 1]) {
          dp[j][k] = dp[j - 1][k - 1] + 1;
        } else {
          dp[j][k] = max(dp[j][k - 1], dp[j - 1][k]);
        }
      }
    }

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

  return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

int dat[1024][1024];
int getLcbLen(char* x, int xe, char* y, int ye){
	cout << xe << ":"<<ye<<endl;
	if(xe <= 0 || ye <= 0) return 0;
	if(dat[xe][ye] != -1) return dat[xe][ye];
	return dat[xe][ye] = (x[xe-1] == y[ye-1] ? 1 + getLcbLen(x, xe-1, y, ye-1) : max(getLcbLen(x, xe-1, y, ye), getLcbLen(x, xe, y, ye-1)));
}

int main() {
	int set;
	scanf("%d", &set);
	
	while(set--){
		char x[1024], y[1024];
		scanf("%s %s", x, y);
		
		for(int i = 0; i < 1024; i++){
			for(int k = 0; i < 1024; k++){
				dat[i][k] = -1;
			}
		}
		printf("%d\n", getLcbLen(x, (int)strlen(x), y, (int)strlen(y)));
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int main(){
  int n;
  int k;
  int count;
  cin>>n;
  char X[1001];
  char Y[1001];
  for(int i=0;i<n;i++){
    cin>>X;
    cin>>Y;
    k=0;
    count=0;
    for(int i=0;X[i]!='\0';i++){
      for(int j=k;Y[j]!='\0';j++){
	if(X[i]==Y[j]){
	  count++;
	  k=j;
	  break;
	}
      }
    }
    cout<<count<<endl;
  }
  return 0;
}

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

string X;
string Y;

int calc(int x, int y){
    if (X[x] == '\0') return 0;
    int tmp1 = calc(x + 1, y);
    int y_next = Y.find(X[x], y);
    if (y_next == string::npos) return 0;
    int tmp2 = calc(x + 1, y_next + 1) + 1;
    return max(tmp1, tmp2);
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> X;
        cin >> Y;
        cout << calc(0, 0) << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#define MAX 1001
using namespace std;
int lcs(string A,string B){
    int X = A.size();
    int Y = B.size();
    int count[MAX][MAX] = {0};
    for(int i=1;i<Y+1;i++){
        for(int j=1;j<X+1;j++){
            if(B[i-1]==A[j-1]){
                count[i][j] = count[i-1][j-1] + 1;
            }else{
                count[i][j] = max(count[i][j-1],count[i-1][j]);
            }
            //cout << count[i][j];
        }
        //cout << endl;
    }
    return count[Y][X];
}
int main(void){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string A,B;
        cin >> A >> B;
        cout << lcs(A,B) << endl;
    }
    return 0;
}

C++: #include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


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

	return 0;
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int dp[1005][1005];

int main() {
    int n; cin >> n;
    REP(k, n){
        REP(i, 1005) REP(j, 1005) dp[i][j] = 0;
        string a, b;
        cin >> a >> b;
        REP(i, a.length()){
            string q = a.substr(i, 1);
            REP(j, b.length()){
                string t = b.substr(j, 1);
                if(q == t){
                    if(i == 0)
                        dp[i][j] = 1;
                    else
                        dp[i][j] = max(dp[i-1][j], dp[i-1][j-1] + 1);
                }
                if (i != 0 && j != 0)
                    dp[i][j] = max(dp[i][j], dp[i][j-1]);
            }
        }
        cout << dp[a.length()-1][b.length()-1] << endl;
    }
    return 0;
}