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++: #define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

long long int INF = 1e18;
using namespace std;

typedef pair<long long int, long long int> P;

long long int DP[1001][1001] = {};

int main(){
	
	int n;
	cin >> n;
	
	for(int loop = 0; loop < n; loop++){
		
		string str1, str2;
		cin >> str1 >> str2;
		
		for(int i = 1; i <= str1.size(); i++){
			for(int j = 1; j <= str2.size(); j++){
				if(str1[i - 1] == str2[j - 1]){
					DP[i][j] = max(max(DP[i - 1][j - 1] + 1, DP[i - 1][j]), DP[i][j - 1]);
				}else{
					DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
				}
			}
		}
		
		cout << DP[str1.size()][str2.size()] << endl;
	}
	return 0;
}

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

using namespace std;


long long L[1010][1010] {0};
int main(){
  int Q;
  cin >> Q;
  for(int i = 0; i < Q; i++){
    string X, Y;
    cin >> X >> Y;
    int xlen = X.length();
    int ylen = Y.length();
    for(int i = 1; i<= xlen; i++){
      for(int k = 1; k <= ylen; k++){
	if(X[i-1] == Y[k-1]){
	  L[i][k] = 1 + L[i-1][k-1];
	}else{
	  L[i][k] = max(L[i][k-1], L[i-1][k]);
	}
      }
    }

    cout << L[xlen][ylen] << endl;
  }

}

C++: #include <iostream>
#include <string>
using namespace	std;
int main(){

  int n;
  string s1,s2;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s1>>s2;
    int dp[1001][1001]={};
    for(int j=1;j<=s2.size();j++){
      for(int k=1;k<=s1.size();k++){
        if(s1[k-1]==s2[j-1]) dp[j][k]=dp[j-1][k-1]+1;
        else dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
      }
    }
    cout<<dp[s2.size()][s1.size()]<<endl;
  }
  return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1005;
int main() {
	int n; cin >> n;
	vv(int, dp, MAX, MAX, 0);
	string X, Y;
	rep(i, 0, n) {
		cin >> X >> Y;
		int len_X = len(X);
		int len_Y = len(Y);
		rep(i, 0, len_X) {
			rep(j, 0, len_Y) {
				dp[i + 1][j + 1] = (X[i] == Y[j] ? dp[i][j] + 1 : max(dp[i][j + 1], dp[i + 1][j]));
			}
		}
		P(dp[len_X][len_Y]);
	}
	return 0;
}

C++: #include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 998244353 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//ld dis(ll a,ll b,ll c,ll d){return sqrt((a-c)*(a-c)+(b-d)*(b-d)) ;}

void chmax(ll &a,ll b){a = max(a,b) ;}

int main(){
	ll q ; cin >> q ;
	for(int tt=0;tt<q;tt++){
		string s,t ;
		cin >> s >> t ;
		vvll dp(s.size()+1,vll(t.size()+1,0)) ;
		for(int i=1;i<=s.size();i++){
			for(int j=1;j<=t.size();j++){
				chmax(dp.at(i).at(j),dp.at(i-1).at(j)) ;
				chmax(dp.at(i).at(j),dp.at(i).at(j-1)) ;
				if(s.at(i-1)==t.at(j-1)) chmax(dp.at(i).at(j),dp.at(i-1).at(j-1)+1) ;
			}
		}
		cout << dp.at(s.size()).at(t.size()) << endl ;
	}
}

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

using namespace std;

int solve(string s1, string s2){
    int L[s1.size()][s2.size()];
    for(int i=0;i<s1.size();i++){
        for(int j=0;j<s2.size();j++){
            if(i==0 || j==0){
                if(s1[i] == s2[j])
                    L[i][j] = 1;
                else
                    L[i][j]=0;
            }
            else if(s1[i] == s2[j]){
                L[i][j] = 1 + L[i-1][j-1];
            }
            else{
                L[i][j] = max(L[i][j-1],L[i-1][j]);
            }
        }
    }
    return L[s1.size()-1][s2.size()-1];
}

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

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

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

int q;
string s, t;
int dp[151][151];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> q;
	rep(k, q) {
		cin >> s >> t;
		rep(i, q) rep(j, q) dp[i][j] = 0;
		rep(i, s.size()) {
			rep(j, t.size()) {
				if (s[i] == t[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
				else {
					dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
				}
			}
		}
		cout << dp[s.size()][t.size()] << "\n";
	}
	return 0;
}