Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

C++: #include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
bool isSubstring(string substr, string t) {
	int n = substr.length();
	int seek = 0;
	rep(i, n) {
		bool ex = 0;
		for (int j = seek; j < t.length(); j++) {
			if (substr[i] == t[j]) {
				ex = 1;
				seek = j + 1;
				break;
			}
		}
		if (ex) {
			continue;
		}
		else {
			return false;
		}
	}
	return true;

}

int LongestCommonSubstring(string s, string t) {
	vector<int>dp(s.length(), 0);
	int n = s.length();
	string lcs = "";
	if (isSubstring(s.substr(n - 1, n), t)) {

		dp[n - 1] = 1;
		lcs = s[n - 1];
	}
	for (int i = n - 2; i >= 0; i--) {
		//string substr = s.substr(i, n);
		string substr = s[i] + lcs;
		int issubst = isSubstring(substr, t);
		if (issubst) lcs = substr;
		dp[i] = dp[i + 1] + issubst;
	}
	return dp[0];
}
int main() {
	//cout << isSubstring("abc", "abcde") << endl;
	//cout << isSubstring("bd", "abcde") << endl;
	//cout << isSubstring("db", "abcde") << endl;

	//cout << LongestCommonSubstring("bacd", "becd") << endl;
	//cout << LongestCommonSubstring("abcd", "becd") << endl;
	int q;
	cin >> q;
	vector<string> s(q);
	vector<string> t(q);
	rep(i, q) {
		cin >> s[i] >> t[i];
	}
	rep(i, q) {
		cout << LongestCommonSubstring(s[i], t[i]) << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool compareg(Pi a, Pi b) {
    if(a.second != b.second){
        return a.second > b.second;
        
    }else{
        return a.first > b.first;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

const vector<ll> d2{0, 1, 0, 2, 0, 1};
const vector<ll> d3{0, 0, 1, 0, 0, 1};
const vector<ll> d5{0, 0, 0, 0, 1, 0};



int main() {

    ll q;
    cin>>q;
    rep(lp,q){
    string X,Y;
    cin>>X>>Y;
    ll N = X.size();
    ll M = Y.size();
    vector<vector<ll>>dp(N+1,vector<ll> (M+1));

    rep(i,N){
        rep(j,M){
            if(X[i] == Y[j]){
                dp[i+1][j+1] = max({dp[i][j] + 1,dp[i+1][j],dp[i][j+1]});
            }else{
                dp[i+1][j+1] = max({dp[i][j] ,dp[i+1][j],dp[i][j+1]});
            }
        }
    }
    
    cout<<dp[N][M]<<endl;
    }
    return 0;
    

}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

vector<vector<int>> dp(2000, vector<int>(2000));

void solve(string s, string t){
  int n = int(s.size());
  int m = int(t.size());

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if(s[i] == t[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
      }else{
        dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
      }
    }
  }

  cout << dp[n][m] << endl;
}

int main(){
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    string s, t;
    cin >> s >> t;
    solve(s, t);
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int q;
string x, y;
int m, n;
int a[1000][1000];
int main()
{
	cin >> q;
	for(int i=0; i<q; i++)
	{
		cin >> x >> y;
		m=x.size();
		n=y.size();
		if(x[0]==y[0])
		{
			a[0][0]=1;
		}
		else
		{
			a[0][0]=0;
		}
		for(int j=1; j<m+n-1; j++)
		{
			if((x[0]!=y[j])&&(a[0][j-1]==0))
			{
				a[0][j]=0;
			}
			else
			{
				a[0][j]=1;
			}
			if((x[j]!=y[0])&&(a[j-1][0]==0))
			{
				a[j][0]=0;
			}
			else
			{
				a[j][0]=1;
			}
			for(int k=1; k<j; k++)
			{
				if(x[k]==y[j-k])
				{
					a[k][j-k]=a[k-1][j-k-1]+1;
				}
				else
				{
					a[k][j-k]=max(a[k-1][j-k], a[k][j-k-1]);
				}
			}
		}
		cout << a[m-1][n-1] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int C[1001][1001];
int lc(string F, string S){
    fill(C[1000],C[1000],0);
    int m = F.size(), n = S.size();
    int len=0;
    for(int i=0; i<m; i++){
        for (int j = 0; j < n; ++j) {
            if (F[i] == S[j]) {
                if (i - 1 >= 0 && j - 1 >= 0)
                    C[i][j] = C[i - 1][j - 1] + 1;
                else
                    C[i][j] = 1;
            } else if (i - 1 >= 0 && j - 1 >= 0) {
                C[i][j] = max(C[i-1][j], C[i][j - 1]);
            }
            len = max(len, C[i][j]);
        }
    }
    return len;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string ar[n*2];
    for (int i = 0; i < n * 2; ++i) {
        cin >> ar[i];
    }
    for (int j = 0; j < n*2; j+=2) {
        cout << lc(ar[j],ar[j+1]) << endl;
    }
    return 0;
}