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>
#include<cstring>
#include<algorithm>
#define MAX_N 1001

int solve(std::string s,std::string t){
        int dp[MAX_N][MAX_N]={0};
        int n,m;
        n=s.size();
       m=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]=std::max(dp[i][j+1],dp[i+1][j]);
                }
        }
        return dp[n][m];
}

int main(){
        int q;
        std::cin>>q;
        for(int i=0;i<q;i++){
                std::string s,t;
                std::cin >> s>>t;
                std::cout<<solve(s,t)<<std::endl;
        }
        return 0;
}

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

int main() {
  int q; cin >> q;
  string A, B;
  for (int i=0; i<q; i++) {
    cin >> A >> B;
    vector<vector<int>> LCS(A.length()+1, vector<int>(B.length()+1,0));
    for (int j=1; j<=A.length(); j++) {
      for (int k=1; k<=B.length(); k++) {
        if(A[j]==B[k]) LCS[j][k]=LCS[j-1][k-1]+1;
        else LCS[j][k]=max(LCS[j-1][k],LCS[j][k-1]);
      }
    }
    cout << max({LCS[A.length()][B.length()],LCS[A.length()-1][B.length()],LCS[A.length()][B.length()-1]}) << "\n";
  }
}

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

string u, v;
vector<vector<int> > memoization;

int lenLCS(int i, int j) {
  int current_max = INT_MIN;
  int attempt;
  if (i == -1)
    return 0;
  if (j == -1)
    return 0;
  if (memoization[i][j] != -1)
    return memoization[i][j];
  if (u[i] == v[j]) {
    attempt = 1 + lenLCS(i-1,j-1);
    if (attempt > current_max)
      current_max = attempt;
  }
  attempt = lenLCS(i-1,j);
  if (attempt > current_max)
    current_max = attempt;
  attempt = lenLCS(i,j-1);
  if (attempt > current_max)
    current_max = attempt;
  memoization[i][j] = current_max;
  return memoization[i][j];
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> v;
    memoization = vector<vector<int> > (u.size(), vector<int> (v.size(), -1));
    cout << lenLCS(u.size()-1, v.size()-1) << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>

#define M 1001

int n;

char x[M],y[M];
 
void lcs(void){
  int i,j;
  int len_x, len_y,graph[M][M];

  len_x=strlen(x);
  len_y=strlen(y);
  for(i=1;i<M;i++){
    for(j=1;j<M;j++){
      graph[i][j]=0;
    }
  }
  for(i=1;i<=len_x;i++){
    for(j=1;j<=len_y;j++){
      if(x[i-1]==y[j-1]) graph[i][j]=graph[i-1][j-1]+1;

      else{
        if(graph[i-1][j]>=graph[i][j-1]) graph[i][j]=graph[i-1][j];
        else graph[i][j]=graph[i][j-1];
      }
    }
  }
  printf("%d\n",graph[len_x][len_y]);
}
     
int main()
{
  int i;
   
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%s",x);
    scanf("%s",y);
    lcs();
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
  
#define MAX 1000
  
int main(){
  int i,j,m,q,x,y,c[MAX+1][MAX+1];
  char X[MAX],Y[MAX];
  
  scanf("%d",&q);
  
  for(i=0;i<strlen(X);i++)
    c[i][0] = 0;
  for(j=0;j<strlen(Y);j++)
    c[0][j] = 0;
  
  for(m=0;m<q;m++){
    scanf("%s",X);
    scanf("%s",Y);
    x = strlen(X);
    y = strlen(Y);
    for(i=0;i<x;i++)
      c[i][0] = 0;
    for(j=0;j<y;j++)
      c[0][j] = 0;
  
    for(i=1;i<=x;i++){
      for(j=1;j<=y;j++){
    if(X[i-1] == Y[j-1])c[i][j] = c[i-1][j-1] + 1;
    else if(c[i-1][j] >= c[i][j-1])c[i][j] = c[i-1][j];
    else c[i][j] = c[i][j-1];
      }
    }
    printf("%d\n",c[x][y]);
  }
  
  return 0;
}

C++: //Longest Common Subsequence
#include <iostream>
#include <string>

using namespace std;

static const int N = 1000;

int lcs(string X, string Y) {
    int c[N + 1][N + 1] = {};
    int maxl = 0, m = int(X.size()), n = int(Y.size());
    X = X;
    Y = Y;
    for(int i = 0; i < m + 1; i++) c[i][m] = 0;
    for(int j = 0; j < n + 1; j++) c[n][j] = 0;
    for(int i = m - 1; i >= 0; i--) {
        for(int j = n - 1; j >= 0; j--) {
            if(X[i] == Y[j]) c[i][j] = 1 + c[i + 1][j + 1];
            else c[i][j] = max(c[i][j + 1], c[i + 1][j]);
        }
    }
    return c[0][0];

}

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;

ll lcs(string s1, string s2)
{
	int m = len(s1);
	int n = len(s2);
	s1 = ' '+s1;
	s2 = ' '+s2;
	int (*mat)[1001];
	mat = new int[1001][1001];
	REP(i, m)
	{
		mat[i][0] = 0;
	}
	REP(i, n)
	{
		mat[0][i] = 0;
	}
	int maxx = 0;
	FOR(i, 1, m+1)
	{
		FOR(j, 1, n+1)
		{
			if (s1[i] == s2[j])
				mat[i][j] = mat[i-1][j-1] + 1;
			else
				mat[i][j] = max(mat[i][j-1], mat[i-1][j]);
			maxx = max(maxx, mat[i][j]);
		}
	}
	delete[] mat;
	return maxx;
}
int main()
{
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	REP(i, n)
	{
		string s1;
		cin >> s1;
		string s2;
		cin >> s2;
		cout << lcs(s1, s2);
	}
	cout << endl;
	return 0;
}