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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

void solve() {
    string s, t;
    cin >> s >> t;
    int sl = s.size(), tl = t.size();
    int dp[sl+1][tl+1];
    for(int i = 0; i < sl+1; i++) for(int j = 0; j < tl+1; j++) dp[i][j] = 0;
    for(int i = 0; i < sl; i++){
        for(int j = 0; j < tl; j++) {
            if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
            chmax(dp[i+1][j+1], dp[i][j+1]);
            chmax(dp[i+1][j+1], dp[i+1][j]);
        }
    }
    cout << dp[sl][tl] << endl;
}

int main(){
    int t;
    cin >> t;
    while(t--) solve();
}

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

using namespace std;
int n;

int main(void){
    // Your code here!
    string S, T;
    int dp[1001][1001];
    cin >> n;
    for(int c = 0; c < n; c++){
        cin >> S >> T;
        
        for(int i = 0; i <= S.size(); i++){
            dp[i][0] = 0;
        }
        for(int j = 0; j <= T.size(); j++){
            dp[0][j] = 0;
        }
        
        for(int i = 0; i < S.size(); i++){
            for(int j = 0; j < T.size(); j++){
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
                if(S[i]==T[j]) dp[i+1][j+1] = max(dp[i][j] + 1, dp[i+1][j+1]);
            }
        }
        
        cout << dp[S.size()][T.size()] << endl;
    }
}

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 = 1e4;
inline int lcs(string X, string Y) {
	vv(int, c, MAX + 1, MAX + 1, 0);
	int m = len(X);
	int n = len(Y);
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	rep(i, 1, m + 1) {
		rep(j, 1, n + 1) {
			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]);
			if(maxl < c[i][j]) maxl = c[i][j];
		}
	}
	return maxl;
}
int main() {
	int n; cin >> n;
	string s1, s2;
	rep(i, 0, n) {
		cin >> s1 >> s2;
		P(lcs(s1, s2));
	}
	return 0;
}

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

int Longest(string x, string y) {
  int L[1001][1001];
  int maxl = -1;
  int xlen = x.size();
  int ylen = y.size();

  x = ' ' + x;
  y = ' ' + y;

  for (int i = 1; i <= xlen; i++) L[i][0] = 0;
  for (int j = 1; j <= ylen; j++) L[0][j] = 0;

  for (int i = 1; i <= xlen; i++) {
    for (int j = 1; j <= ylen; j++) {
      if (x[i] == y[j])
        L[i][j] = L[i-1][j-1] + 1;
      else
        L[i][j] = max(L[i][j-1], L[i-1][j]);

      maxl = max(maxl, L[i][j]);
    }
  }

  return maxl;
}

int main() {
  string X, Y;
  int n;
  int result[10000];

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> X;
    cin >> Y;
    result[i] =  Longest(X, Y);
    cout << result[i] << endl;
  }

  


  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int q=0;q<n;q++){
        string s,t;
        cin>>s>>t;
        int ss=s.length(),ts=t.length();
        int dp[ss+5][ts+5];
        for(int i=0;i<ss+5;i++){
            for(int j=0;j<ts+5;j++)dp[i][j]=0;
        }
        for(int i=0;i<ss;i++){
            for(int j=0;j<ts;j++){
                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[ss][ts]<<endl;
    }
}

C++: #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int q, n, m, dp[1007][1007]; string s, t;
int main() {
	cin >> q;
	while(q--) {
		cin >> s >> t;
		n = s.size(), m = t.size();
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				dp[i][j] = (s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]));
			}
		}
		cout << dp[n][m] << endl;
	}
}

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

#define MAX 1000

using namespace std;


int m[MAX + 2][MAX + 2];
int lcs(string x, string y)
{
    for (int i = 0; i <= y.length(); i++)
        for (int j = 0; j <= x.length(); j++)
            m[i][j] = 0;

    for (int i = 1; i <= y.length(); i++) {
        for (int j = 1; j <= x.length(); j++) {
            if (x[j - 1] == y[i - 1]) {
                m[i][j] = m[i - 1][j - 1] + 1;
            } else {
                m[i][j] = max(m[i - 1][j], m[i][j - 1]);
            }
        }
    }

    return m[y.length()][x.length()];
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string x, y;
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
}