Go: package main

import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	"strings"
	"sort"
)

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				} else {
					dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				}
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

C++: #include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;

struct edge{
  int from,to,cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef pair<int , int> P;
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
int E,V;
edge es[100001];
int kruskal(){
  sort(es,es+E,comp);
  init(V);
  int res = 0;
  for(int i=0;i<E;i++){
    edge e = es[i];
    if(!same(e.to,e.from)){
      unite(e.to,e.from);
      res += e.cost;
    }
  }
  return res;
}


int main()
{
  int co=0,dp[1001][1001];
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[1][0] = 0;
  string x,y;
  cin >> co;
  REP(i,co){
    cin >> x;
    cin >> y;
    REP(i,x.length()+1)REP(j,y.length()+1){
      if(i == 0 || j == 0)
        dp[i][j] = 0;
      else{
      if(x[i-1] == y[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[x.length()][y.length()] << endl;
  }
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

void solve(string S, string T) {
    vector<vector<int>> dp(S.size() + 1, vector<int>(T.size() + 1, 0));
    REP(i, S.size() + 1) REP(j, T.size() + 1) {
        if (S[i - 1] == T[j - 1]) dp[i][j] = max({dp[i - 1][j - 1] + 1, dp[i - 1][j], dp[i][j - 1]});
        else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    }
    cout << dp[S.size()][T.size()] << endl;
    return;
}

int main() {
    int q;
    cin >> q;
    rep(i, q) {
        string X, Y;
        cin >> X >> Y;
        solve(X, Y);
    }
    return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INFLL=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void solve_(){
     string a,b;
    cin >> a >> b;
    
    static int dp[1000][1000];
    fill_n((int*)dp,1000*1000,0);
    
    rep(i,0,a.size()){
        rep(j,0,b.size()){
            if(i!=0) dp[i][j]=dp[i-1][j];
            if(j!=0) dp[i][j]=max(dp[i][j],dp[i][j-1]);
            
            if(a[i]!=b[j]) continue;
            
            if(i==0||j==0) dp[i][j]=1;
            else dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
        }
    }
    
    cout << dp[a.size()-1][b.size()-1] << endl;
}

void solve(){
    int n;
    cin >> n;
    rep(i,0,n) solve_();
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>

using namespace std;

int main()
{
    int N;
    int data[1001][1001]={};
    cin>>N;
    string str1,str2;
    for(int i=0;i<N;i++){
        cin>>str1>>str2;
        for(int i=0;i<str1.length();i++){
            for(int j=0;j<str2.length();j++){
                if(str1[i]==str2[j]){
                    data[i+1][j+1]=data[i][j]+1;
                }else{
                    data[i+1][j+1]=data[i+1][j]>data[i][j+1]?data[i+1][j]:data[i][j+1];
                }
            }
        }
        cout<<data[str1.length()][str2.length()]<<endl;
    }
}

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(); // 文字列２の長さ
	int maxl = 0; // 文字列の最長の長さ
	X = ' ' + X; // X[0]に空白を挿入
	Y = ' ' + Y; // Y[0]に空白を挿入

	c[0][0] = 0;
	for (int i = 1; i <= m; i++) c[i][0] = 0;
	for (int j = 1; 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]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}

	// 配列c[][]の中身確認
	/*for (int i = 0; i <= m; i++) {
		for (int j = 0; j <= n; j++) {
			cout << c[i][j] << ", ";
		}
		cout << endl;
	}*/

	return maxl;

}

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

	return 0;
}