Go: package main

import (
	"bufio"
	"os"
	"io"
	"strconv"
	"math"
	"fmt"
)

var (
	nstr   func() string
	stdout *bufio.Writer
)

func init() {
	nstr = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func main() {
	defer stdout.Flush()

	n := nint()
	xList := make([]string, n)
	yList := make([]string, n)

	for i:=0;i<n ;i++  {
		xList[i] = nstr()
		yList[i] = nstr()
	}

	for i := 0; i<n	; i++  {
		fmt.Println(lcs(xList[i], yList[i]))
	}

}

func lcs(x string, y string) int{
	var m = len(x)
	var n = len(y)

	c := make([][]int, m+1)
	for i:= range c{
		c[i] = make([]int, n+1)
	}
	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] = int(math.Max(float64(c[i-1][j]), float64(c[i][j-1])))
			}


		}
	}
	return c[m][n]

}


func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func nint64() int64 {
	i, err := strconv.ParseInt(nstr(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func nint() int {
	return int(nint64())
}

func getIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nint()
	}
	return b
}

func getStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = nstr()
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2)
	} else {
		return strconv.FormatInt(i64, 2)
	}
}

func strReverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

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

int main(){

  int n;
  int dp[1111][1111];

  cin >> n;
  while(n--){
    string str1, str2;
    cin >> str1 >> str2;

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

    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] = dp[i-1][j-1] + 1;
        }else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
    }
    cout << dp[str1.size()][str2.size()] << endl;

  }
}

C++: #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int dp[1001][1001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  vector<string> xs(q), ys(q);
  for (int i = 0; i < q; i++) {
    cin >> xs[i] >> ys[i];
  }

  for (int i = 0; i < q; i++) {
    fill(dp[0], dp[1001], 0);
    string x = xs[i], y = ys[i];
    for (int j = 0; j < x.size(); j++) {
      for (int k = 0; k < y.size(); k++) {
        if (x[j] == y[k]) {
          dp[j + 1][k + 1] = dp[j][k] + 1;
        } else {
          dp[j + 1][k + 1] = max(dp[j][k + 1], dp[j + 1][k]);
        }
      }
    }

    cout << dp[x.size()][y.size()] << endl;
    ;
  }
  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>

using namespace std;

typedef long long ll;

int get_LCS(string x, string y){
  int nx = x.size(), ny = y.size();
  int dp[nx+1][ny+1];
  for(int i=0;i<=ny;i++) dp[0][i] = 0;
  for(int i=0;i<=nx;i++) dp[i][0] = 0;
  for(int i=1;i<=nx;i++){
    for(int j=1;j<=ny;j++){
      if(x[i] == y[j]) dp[i][j] = dp[i-1][j-1] + 1;
      else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
    }
  }
  return dp[nx][ny];
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int q; cin >> q;
  for(int i=0;i<q;i++){
    string x, y; cin >> x >> y;
    cout << get_LCS(x, y) << endl;
  }
}

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

int lcs(string s1,string s2)
{
	int m = s1.size();
	int n = s2.size();
	int c[1005][1005];
	for (int i = 1; i <= m; i++)c[i][0] = 0;
	for (int j = 1; j <= n; j++)c[0][j] = 0;
	int maxz = 0;
	s1 = " " + s1;
	s2 = " " + s2;
	for(int i=1;i<=m;i++)
		for (int j = 1; j <= n; j++) {
			if (s1[i] == s2[j])
				c[i][j] = c[i-1][j-1] + 1;
			else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxz = max(maxz, c[i][j]);
		}
	return maxz;
}
int main()
{
	int N;
	scanf("%d", &N);
	while (N--) {
		string s1, s2;
		cin >> s1>>s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
}

C++: /*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp
*/
#include<iostream>
#include<string>
using namespace std;

//最長共通部分列
int LCS(string x , string y){
  int x_len=x.size();
  int y_len=y.size();
  int dp[x_len+1][y_len+1];
  //初期化
  for(int i=0;i<=x_len;i++){
    for(int j=0;j<=y_len;j++){
      dp[i][j]=0;
    }
  }
  for(int i=0;i<x_len;i++){
    for(int j=0;j<y_len;j++){
      if(x[i]==y[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]);
      }
    }
  }
  return dp[x_len][y_len];
}
int main(){
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    string str1,str2;
    cin>>str1>>str2;
    cout<<LCS(str1,str2)<<"\n";
  }
}

C++: # include<iostream>
# include<string>
# include<algorithm>
using namespace std;
# define N 300
# define M 1000
# define L 1001

int main(){
    int q;
    cin >> q;
    string iranai; iranai = cin.get(); //改行文字を排除

    string A[N][M];
    int cnt[N];
    for(int i=0; i<(q*2); i++){
        int j=0;
        while((A[i][j] = cin.get()) != "\n"){
            j++;
            cnt[i]++;
        }
    }

    for(int k=0; k<(q*2); k+=2){
        int B[L][L];
        for(int i=0; i<=cnt[k]; i++){
            string str;
            if(i!=0) str = A[k][i-1];
            for(int j=0; j<=cnt[k+1]; j++){
                if(i==0 || j==0) B[i][j] = 0;
                else if(A[k+1][j-1] != str) B[i][j] = max(B[i-1][j], B[i][j-1]);
                else B[i][j] = B[i][j] = B[i-1][j-1] + 1;
            }
        }
        cout << B[cnt[k]][cnt[k+1]] << "\n";
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

int dp[10005][10005];

int main() {
  int n;
  cin >> n;
  rep(k, n) {
    string a, b;
    cin >> a >> b;
    int m = a.size();
    int n = b.size();
    rep(i, 10005) {
      dp[0][i] = 0;
      dp[i][0] = 0;
    }
    for (int i = 1; i < n + 1; i++) {
      for (int j = 1; j < m + 1; j++) {
        if (b[i-1] == a[j-1]) {
          dp[i][j] = max(max(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1] + 1);
        } else {
          dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
      }
    }
    cout << dp[n][m] << endl;
  }

  return 0;
}