Go: package main

import "fmt"

func main() {
	var nPairs int
	fmt.Scanln(&nPairs)

	var a, b string
	for i := 0; i < nPairs; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Println(lcsSize(a, b))
	}
}

func lcsSize(sa, sb string) int {
	dp := make([][]int, len(sa)+1)
	for i := 0; i <= len(sa); i++ {
		dp[i] = make([]int, len(sb)+1)
	}

	for a := 1; a <= len(sa); a++ {
		for b := 1; b <= len(sb); b++ {
			if sa[a-1] == sb[b-1] {
				dp[a][b] = dp[a-1][b-1] + 1
			} else {
				dp[a][b] = max(dp[a][b-1], dp[a-1][b])
			}
		}
	}

	return dp[len(sa)][len(sb)]
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

class TLongistCommons
{
	std::vector<std::vector<int> > FTable;
	const std::string& FSequenceX;
	const std::string& FSequenceY;
	
	int MeasureCommons(int PrefixX, int PrefixY);
public:
	TLongistCommons(const std::string& SequenceX, const std::string& SequenceY);
	
	int Length();
};

TLongistCommons::TLongistCommons(const std::string& SequenceX, const std::string& SequenceY)
: FSequenceX(SequenceX), FSequenceY(SequenceY), FTable(SequenceX.length() + 1, std::vector<int>(SequenceY.length() + 1, -1))
{
}

int TLongistCommons::MeasureCommons(int PrefixX, int PrefixY)
{
	if(FTable[PrefixX][PrefixY] < 0){
		int Longest;
		if(PrefixX == 0 || PrefixY == 0){
			Longest = 0;
		}else if(FSequenceX[PrefixX - 1] == FSequenceY[PrefixY - 1]){
			Longest = MeasureCommons(PrefixX - 1, PrefixY - 1) + 1;
		}else{
			Longest = std::max(MeasureCommons(PrefixX - 1, PrefixY), MeasureCommons(PrefixX, PrefixY - 1));
		}
		FTable[PrefixX][PrefixY] = Longest;
	}
	return FTable[PrefixX][PrefixY];
}

int TLongistCommons::Length()
{
	return MeasureCommons(FSequenceX.length(), FSequenceY.length());
}

int MeasureLcs(const std::string& SequenceX, const std::string& SequenceY)
{
	TLongistCommons Subsequence(SequenceX, SequenceY);
	return Subsequence.Length();
}

int main()
{
	int Count;
	std::cin >> Count;
	for(int i = 0; i < Count; ++i){
		std::string SequenceX, SequenceY;
		std::cin >> SequenceX;
		std::cin >> SequenceY;
		std::cout << MeasureLcs(SequenceX, SequenceY) << std::endl;
	}
	return 0;
}

C++: #include "iostream"
#include"string"
#include"algorithm"
using namespace std;
int c[1001][1001];
int lcs(string X,string Y) {
	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 = 0; 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()
{
	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<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;
const ll MOD=1000000007;






int main(){
    ll q;
    cin>>q;
    while(q--){
        
        
    string a,b;
    cin>>a>>b;
    
    vector<set<ll>> w(300);
    vector<vector<ll>> dp(2000);
    for(int i=0;i<dp.size();i++){dp[i].resize(2000,E);}
    
    for(int i=0;i<b.size();i++){
        w[b[i]].insert(i);
    }
    
    ll mx=0;
    
    for(int i=0;i<a.size();i++){
        for(int t=0;t<b.size()+100;t++){
            if(t==0 && !w[a[i]].empty() && *w[a[i]].begin()<dp[i][t]){
                dp[i+1][t]=*w[a[i]].begin();
                mx=max(mx,(ll)t+1);
            }
            else if(w[a[i]].upper_bound(dp[i][t-1])!=w[a[i]].end() && *w[a[i]].upper_bound(dp[i][t-1])<dp[i][t]){
                dp[i+1][t]=*w[a[i]].upper_bound(dp[i][t-1]);
                mx=max(mx,(ll)t+1);
            }
            else{dp[i+1][t]=dp[i][t];}
        }
    }
    cout<<mx<<endl;
        
        
    }
    
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
  int n;
  char x[1001],y[1001];
  int dp[1002][1002];
  


  //load n;
  cin >>n;
  for(int i=0;i<n;i++){
    //initialize
    for(int i=0;i<1002;i++){
      for(int j=0;j<1002;j++){
	dp[i][j]=0; 
      }
    }
    //load string
    scanf("%s",x);
    scanf("%s",y);
    //dp
    for(int j=0;j<strlen(x);j++){
      for(int k=0;k<strlen(y);k++){
	if(x[j]==y[k]){
	  dp[j+1][k+1]=dp[j][k]+1;
	}

	else{
 
	  if(dp[j][k+1]>dp[j+1][k]){
	    dp[j+1][k+1]=dp[j][k+1];
	  }

	  else{
	    dp[j+1][k+1]=dp[j+1][k];
	  }
	}
      }
    }

    //print
    cout <<dp[strlen(x)][strlen(y)]<<endl;
  }



  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;


int main(){
    string str1,str2;
    int n, len1, len2;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        cin>>str1>>str2;
        //scanf("%s",str1);
        //scanf("%s",str2);
        len1 = str1.size();
        len2 = str2.size();
        str1 = ' '+str1;
        str2 = ' '+str2;
        int c[len1+1][len2+1];
        for(int i=0;i<=len1;++i) c[i][0] = 0;
        for(int i=0;i<=len2;++i) c[0][i] = 0;
        for(int i=1;i<=len1;++i){
            for(int j=1;j<=len2;++j){
                if(str1[i]==str2[j]){
                    c[i][j] = c[i-1][j-1]+1;
                }
                else{
                    c[i][j] = max(c[i-1][j],c[i][j-1]);
                }
            }
        }
        printf("%d\n",c[len1][len2]);
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int main(){
  int q;
  cin>>q;
  for(int cn=0;cn<q;cn++){
    string x,y;
    cin>>x>>y;
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=x.size();i++){
      for(int j=1;j<=y.size();j++){
	if(x[i-1]==y[j-1])dp[i][j]=dp[i-1][j-1]+1;
	dp[i][j]=max(dp[i-1][j],dp[i][j]);
	dp[i][j]=max(dp[i][j-1],dp[i][j]);
      }
    }
    cout<<dp[x.size()][y.size()]<<endl;
  }
  return 0;
}

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

int lcs(string X, string Y) {
  int dp[1000 + 1][1000 + 1];
  int max = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (unsigned int i = 1; i <= X.size() - 1; i++)
    dp[i][0] = 0;

  for (unsigned int i = 1; i <= Y.size() - 1; i++)
    dp[0][i] = 0;
  for (unsigned int i = 1; i <= X.size() - 1; i++) {
    for (unsigned int j = 1; j <= Y.size() - 1; j++) {
      if (X[i] == Y[i])
	dp[i][j] = dp[i - 1][j - 1] + 1;
      else if (dp[i - 1][j] >= dp[i][j - 1])
	dp[i][j] = dp[i - 1][j];
      else
	dp[i][j] = dp[i][j - 1];

      max = (max < dp[i][j]) ? dp[i][j] : max;
    }
  }

  return max;
}

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    string X, Y;
    cin >> X >> Y;

    cout << lcs(X, Y) << endl;
  }

  return 0;
}