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<iostream>
#include<string>
int main()
{
  int n;
  int an[1000];
  int l=0;
  std::cin>>n;
  std::string x;
  std::string y;
  int ans[1001][1001];
  int j,k;
  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<=1000;j++){
      for(int k=0;k<=1000;k++){
	ans[j][k]=0;
      }
    }
    for(int j=1;j<=x.size();j++){
      for(int k=1;k<=y.size();k++){
	if(x[j]==y[k]){
	  ans[j][k]=ans[j-1][k-1]+1;
	}else{
	  if(ans[j][k-1]>ans[j-1][k]){
	    ans[j][k]=ans[j][k-1];
	  }else{
	    ans[j][k]=ans[j-1][k];
	  }
	}
      }
    }
    std::cout<<ans[x.size()-1][y.size()-1]<<'\n';  
  }
  return 0;
}

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

static int lc[1000][1000];
static std::string X, Y;

int count(int idx_x, int idx_y) {
    if (lc[idx_x][idx_y] != -1) {
        return lc[idx_x][idx_y];
    }

    int maximum = 0;
    
    if (X[idx_x] == Y[idx_y]) {
        if (idx_x > 0 && idx_y > 0) {
            maximum = std::max(maximum, count(idx_x - 1, idx_y - 1));
        }
        lc[idx_x][idx_y] = maximum + 1;
    } else {
        if (idx_x > 0) {
            maximum = std::max(maximum, count(idx_x - 1, idx_y));
        }
        if (idx_y > 0) {
            maximum = std::max(maximum, count(idx_x, idx_y - 1));
        }
        lc[idx_x][idx_y] = maximum;
    }
    return lc[idx_x][idx_y];
}

int LongestCommon() {
    for (int i = 0; i < X.length(); i++) {
        for (int j = 0; j < Y.length(); j++) {
            lc[i][j] = -1;
        }
    }
    return count(X.length() - 1, Y.length() - 1);
}

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

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, al, bl;
  string k, l;
  int ans[1001][1001];
  cin >> N;

  rep(i, N){
    cin >> k;
    cin >> l;

    al = k.length();
    bl = l.length();


    rep(j, al+1){
      rep(s, bl+1){
        ans[j][s] = 0;
      }
    }

    rep(j, al){
      rep(s, bl){
        if(k[j] == l[s]){
          ans[j+1][s+1] = max(ans[j+1][s], max(ans[j][s+1], ans[j][s] + 1));
        } else{
          ans[j+1][s+1] = max(ans[j+1][s], ans[j][s+1]);
        }
      }
    }

    cout << ans[al][bl] << "\n";



  }
}

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

int dp[1001][1001];
int main() {
	int b;
	scanf("%d", &b);
	char e[1001];
	char f[1001];
	for (int c = 0; c < b; c++) {
		scanf("%s%s", e, f);
		for (int g = 0; g <= strlen(e); g++) {
			for (int h = 0; h <= strlen(f); h++) {
				dp[g][h] = 0;
			}
		}
		for (int g = 1; g <= strlen(e); g++) {
			for (int h = 1; h <= strlen(f); h++) {
				if (e[g] == f[h]) {
					dp[g][h] = dp[g - 1][h - 1] + 1;
				}
				else {
					dp[g][h] = max(dp[g][h - 1], dp[g - 1][h]);
				}
			}
		}
		printf("%d\n", dp[strlen(e)][strlen(f)]);
	}
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int q;
string x, y;
int dp[1111][1111];

void solve() {
   for (int i = 1; i <= x.size(); i++) {
      for (int j = 1; j <= y.size(); j++) {
         if (x[i] == y[j]) {
            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;
}

int main() {
   cin >> q;
   while (q--) {
      fill(dp[0], dp[1111], 0);
      cin >> x >> y;
      solve();
   }

   return 0;
}

C++: #include<iostream>
#include<vector>b
using namespace std;
int main()
{
	int kurikaeshi;
	vector<int> answer;
	cin >> kurikaeshi;
	for (int variable = 0;variable < kurikaeshi;++variable) {
		char X[1024], Y[1024];
		int LX = 0, LY = 0;
		vector<vector<int>> L;
		cin >> X >> Y;
		for (int i = 0;X[i] != 0;++i) LX += 1;
		for (int j = 0;Y[j] != 0;++j) LY += 1;
		L.resize(LX+1);
		for (int k = 0;k < LX + 1;++k) L[k].resize(LY+1);
		for (int i = 0;X[i] != 0;++i) {
			for (int j = 0;Y[j] != 0;++j) {
				if (i == 0 || j == 0) {
					L[i][j] = 0;
				}
				else if (X[i] == Y[j]) {
					L[i+1][j+1] = L[i+1][j] + 1;
				}
				else {
					L[i+1][j+1] = L[i][j+1] > L[i+1][j] ? L[i][j+1] : L[i+1][j];
				}
			}
		}
		answer.push_back(L[LX][LY]+1);
	}
	for (int variable = 0;variable < kurikaeshi;++variable) {
		cout << answer[variable] << endl;
	}
}