Go: package main

import "fmt"

func main() {
	var nPairs int
	fmt.Scanln(&nPairs)

	var a, b string
	for i := 0; i < nPairs; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Println(lcsSize(a, b))
	}
}

func lcsSize(sa, sb string) int {
	dp := make([][]int, len(sa)+1)
	for i := 0; i <= len(sa); i++ {
		dp[i] = make([]int, len(sb)+1)
	}

	for a := 1; a <= len(sa); a++ {
		for b := 1; b <= len(sb); b++ {
			if sa[a-1] == sb[b-1] {
				dp[a][b] = dp[a-1][b-1] + 1
			} else {
				dp[a][b] = max(dp[a][b-1], dp[a-1][b])
			}
		}
	}

	return dp[len(sa)][len(sb)]
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

C++: #include<stdio.h>

int hantei(char x[], char y[]) {
  int xn = 0, yn = 0, flag = 0, i, j, max = 0;
  int c[1001][1001];
  
  while (flag == 0)
  {
    if (x[xn] >= 97 && x[xn] <= 122)
    {
      xn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  flag = 0;
  
  while (flag == 0)
  {
    if (y[yn] >= 97 && y[yn] <= 122)
    {
      yn++;
    }
    else
    {
      flag = 1;
    }
  }
  for (i = 1; i < xn + 1; i++) c[i][0] = 0;
  for (j = 1; j < yn + 1; j++) c[0][j] = 0;
  
  for (i = 1; i < xn + 1; i++)
  {
    for (j = 1; j < yn + 1; 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];
      }
      if (max < c[i][j]) max = c[i][j];
    }
  }
  
  return max;
}

int main(void) {
  char x[1000], y[1000];
  int q, i;
  
  scanf("%d", &q);
  
  for (i = 0; i < q; i++)
  {
    scanf("%s", x);
    scanf("%s", y);
    printf("%d\n", hantei(x, y));
  }
  
  return 0;
}

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

static const int N = 1000;

int lcs(string x, string y) {
    int c[N + 1][N + 1];
    int m = x.size();
    int n = y.size();
    x = ' ' + x;
    y = ' ' + y;
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 0; j <= n; j++) c[0][j] = 0;

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            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]);
            }
        }
    }

    return c[m][n];
}

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

C++: #include <iostream>
#include<string>
using namespace std;
int main(void){
    // Your code here!
    // Your code here!
    int q;
    cin>>q;
    string x[q],y[q];
   
    //string s[q*2];
    string tmp;
    for(int i=0;i<q;i++){
        cin>>tmp;
        x[i]=tmp;
        cin>>tmp;
        y[i]=tmp;
    }
    for(int i=0;i<q;i++){
        //cout<<sizeof(x)/sizeof(x[0])<<" "<<sizeof(y[i])<<"\n";
        int dp[x[i].length()+1][y[i].length()+1];
        for(int j=0;j<x[i].length()+1;j++){ 
            for(int k=0;k<y[i].length()+1;k++){ 
                if(j==0 || k==0){
                    dp[j][k]=0;
                }
                else if(x[i][j-1]==y[i][k-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[x[i].length()][y[i].length()]<<"\n";
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> ans(n);
	for (int cou = 0;cou < n;cou++) {
		string s, t;
		cin >> s >> t;
		int S = s.size(), T = t.size();
		vector<vector<int> > dp(S + 1, vector<int>(T + 1, 0));
		for (int i = 0;i < S;i++) {
			for (int j = 0;j < T;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]);
				}
			}
		}
		ans[cou] = dp[S][T];
	}
	for (int i = 0;i < n;i++) {
		cout << ans[i] << endl;
	}
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

vvi dp;
string gx, gy;
int dfs(int ix, int iy) {
    if (ix == gx.length() or iy == gy.length()) {
        return 0;
    }
    if (dp[ix][iy] != -1) return dp[ix][iy];

    if (gx[ix] != gy[iy]) {
        int c1 = dfs(ix+1, iy);
        int c2 = dfs(ix, iy+1);
        dp[ix][iy] = max(c1, c2);
    } else {
        int c1 = dfs(ix+1, iy+1)+1;
        int c2 = dfs(ix, iy+1);
        dp[ix][iy] = max(c1, c2);
    }

    return dp[ix][iy];
}

void solve(string x, string y) {
    gx = x, gy = y;
    dp = vvi(1005, vi(1000, -1));
    cout << dfs(0, 0) << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    REP(i, n) {
        string x, y;
        cin >> x >> y;
        solve(x, y);
    }

    return 0;
}

C++: /*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

int dp[MAX_N + 1][MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int qn;
  cin >> qn;

  while (qn--) {
    string x, y;
    cin >> x >> y;

    int xn = x.size(), yn = y.size();

    memset(dp, 0, sizeof(dp));

    for (int i = 0; i <= xn; i++)
      for (int j = 0; j <= yn; j++) {
	if (i < xn && j < yn && x[i] == y[j] &&
	    dp[i + 1][j + 1] < dp[i][j] + 1)
	  dp[i + 1][j + 1] = dp[i][j] + 1;

	if (i < xn && dp[i + 1][j] < dp[i][j])
	  dp[i + 1][j] = dp[i][j];

	if (j < yn && dp[i][j + 1] < dp[i][j])
	  dp[i][j + 1] = dp[i][j];
      }

    printf("%d\n", dp[xn][yn]);
  }

  return 0;
}

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

using namespace std;

int lcs (string x, string y) {

    int m, n, c[1001][1001], i, j, maxl = 0;

    m = x.size();
    n = y.size();

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

    for (i = 0; i <= m; i++) {
        c[i][0] = 0;
    }
    for (j = 1; j <= n; j++) {
        c[0][j] = 0;
    }

    for (i = 1; i <= m; i++) {
            for (j = 1; j <= n; j++) {

                if (x[i - 1] == y[j - 1]) {
                    c[i][j] = c[i - 1][j - 1] + 1;
                } else {
                    c[i][j] = max (c[i - 1][j], c[i][j - 1]);
                }

                maxl = max (maxl, c[i][j]);

            }
    }

    return maxl;

}



int main () {

    int N, i;
    string x, y;

    cin >> N;

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

    }

    return 0;

}