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(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	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<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int LCS(const char* s1, const char* s2){
	int i,j;
	int n1=strlen(s1);
	int n2=strlen(s2);
	int dp[n1+1][n2+1];
	for(i=0;i<=n1;i++)dp[i][0]=0;
	for(j=0;j<=n2;j++)dp[0][j]=0;
	for(i=1;i<=n1;i++){
		for(j=1;j<=n2;j++){
			if(s1[i-1]==s2[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	return dp[n1][n2];
}

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

C++: def lcs(x, y)
  for i in range(1, len(x)):
    for j in range(1, lem(y)):
      if x[i] = y[j]:
        c[i][j] = c[i-1][j-1] + 1
      elif c[i-1][j]>c[i][j-1]:
        c[i][j] = c[i-1][j]
      else:
        c[i][j] = c[i][j-1]






q  = input()
x = [' ' for row in range(n+1)]
y = [' ' for row in range(n+1)]
c = [[' ' for col in range(1000)] for row in range(1000)]
for i in range(q):
  x = input()
  y = input()
  print lcs(x, y)

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int lcs(string X, string Y) {
  vector<vector<int>> c(2000, vector<int>(2000));
  int m = X.length();
  int n = Y.length();
  int maxl = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X.at(i - 1) == Y.at(j - 1)) {
        c.at(i).at(j) = c.at(i - 1).at(j - 1) + 1;
      } else {
        c.at(i).at(j) = max(c.at(i - 1).at(j), c.at(i).at(j - 1));
      }
      maxl = max(maxl, c.at(i).at(j));
    }
  }
  return maxl;
}

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

  vector<string> x(q);
  vector<string> y(q);
  rep(i, q) {
    cin >> x.at(i);
    cin >> y.at(i);
  }

  rep(i, q) { cout << lcs(x.at(i), y.at(i)) << endl; }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'

int dp[1010][1010];

void solve(){
    string s,t;
    cin >> s >> t;

    int n = s.size();
    int m = t.size();
    memset(dp,0,sizeof(dp));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(s[i] == t[j]){
                dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + 1);
            }
            dp[i+1][j+1] = max(max(dp[i+1][j+1],dp[i+1][j]),dp[i][j+1]);
        }
    }
    cout << dp[n][m] << endl;
}

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

    while(q--){
        solve();
    }
}

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

// Longest Common Subsequence

class LCS {
    string S, T;
    vector <vector<int>> dp;

public:
    LCS(string &s, string &t) : S(s), T(t) {
        int sl = S.size(), tl = T.size();
        dp.assign(sl + 1, vector<int>(tl + 1, 0));

        for (int i = 0; i < sl; i++) {
            for (int j = 0; j < tl; 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]);
                }
            }
        }
    }

    int len() { return dp[S.size()][T.size()]; }

    string str() {
        string ret = "";
        int i = S.size(), j = T.size();
        while (dp[i][j]) {
            if (S[i - 1] == T[j - 1]) {
                i--, j--;
                ret = S[i] + ret;
            } else if (dp[i - 1][j] > dp[i][j - 1]) {
                i--;
            } else {
                j--;
            }
        }
        return ret;
    }
};


// verified
//   http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp
void AOJ_ALDS1_10_C() {
    int q;
    cin >> q;
    while (q--) {
        string x, y;
        cin >> x >> y;
        LCS lcs(x, y);
        cout << lcs.len() << "\n";
    }
}


// verified
//   https://atcoder.jp/contests/dp/tasks/dp_f
void AtCoder_2019_1_6_F() {
    string s, t;
    cin >> s >> t;
    LCS lcs(s, t);
    cout << lcs.str() << '\n';
}

int main() {
    AOJ_ALDS1_10_C();
    // AtCoder_2019_1_6_F();
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

const ll MAX_N=1001;

ll lcs(string a,string b){

  ll c[MAX_N][MAX_N];
  ll as=a.size();
  ll bs=b.size();
  a.insert(0," ");
  b.insert(0," ");

  CLR(c,0);
  rep(i,1,as+1){
    rep(j,1,bs+1){
      if(a[i]==b[j])c[i][j]=c[i-1][j-1]+1;
      else chmax(c[i][j],max(c[i-1][j],c[i][j-1]));
    }
  }

  return c[as][bs];
}

int main(){

  ll n;cin>>n;

  while(n--){
    string a,b;cin>>a>>b;
    out(lcs(a,b));
  }

  return 0;
}