Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

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

func lcs(a, b string) int {
	lenA := len(a)
	lenB := len(b)
	dp := make([][]int, lenA+1)
	for i := range dp {
		dp[i] = make([]int, lenB+1)
	}

	for i := 1; i <= lenA; i++ {
		for j := 1; j <= lenB; j++ {
			if a[i-1] == b[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = max(dp[i][j-1], dp[i-1][j])
			}
		}
	}
	return dp[lenA][lenB]
}

func main() {
	n := scanInt()
	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		a := scanString()
		b := scanString()
		fmt.Fprintln(w, lcs(a, b))
	}
	w.Flush()
}

C++: #include<cstdio>
#include<stdlib.h>
#include<iostream>
using namespace std;

const int maxn = 1005;

int T[maxn][maxn];

int calculateCommon(string s1,string s2){
	for(int i = 0;i <= s1.length();i++){
		for(int j = 0;j <= s2.length();j++){
			if(i == 0 || j == 0){
				T[i][j] = 0;
			}else{
				if(s1[i - 1] == s2[j - 1]){
					T[i][j] = T[i - 1][j - 1] + 1;
				}else{
					T[i][j] = (T[i][j - 1] < T[i - 1][j]) ? T[i - 1][j]:T[i][j - 1];
				}
			}
	//		cout << "T[" << i << "][" << j << "] = " << T[i][j] << endl;
		}
	}
	return T[s1.length()][s2.length()];
}

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

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

using namespace std;

#if 0
http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2065462#1
#endif

int n;
string a, b;
string x[10000], y[10000];




int main(){
  cin >> n;
  while(n != 0){
    n = n -1;
    int longest[1000][1000];
    cin >> a;
    cin >> b;
    a = ' ' + a;
    b = ' ' + b;
    int mm = 0;
    /*
    for(int i = 0; i < a.size(); ++i){
      for(int j = 0; j < b.size(); ++j){
        
        x[i] = a;
        y[j] = b;
      }
    }
    */
   //longest[0][0] =0;
   for(int i = 1; i <= a.size(); ++i){
     longest[i][0] = 0;
    }
   for(int j = 1; j <= b.size(); ++j){
     longest[0][j] = 0;
   }
    for(int i = 1; i <= a.size(); ++i){
      for(int j = 1; j <= b.size(); ++j){
        
        /*
        if(i <= 0 || j <=0){
          longest[i][j] = 0;
        }
        */
        if(a[i] == b[j]){
          longest[i][j] = 1 + longest[i-1][j - 1];
        }
        else{
          longest[i][j] = max(longest[i][j-1], longest[i-1][j]);
        }
        mm = max(mm, longest[i-1][j-1]);
      }
    }
    //cout << a[1] << endl;
    cout << mm << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
    using namespace std;
int lcs(string x,string y){
    int c[1010][1010];
    int m = x.size();
    int n = y.size();
    int maxl=0;
    x = ' '+x;
    y = ' '+y;
    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]);
        }
        
    }
    return maxl;
}
int main(){
    int q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

C++: ///
// File:  alds1_10_c.cpp
// Author: ymiyamoto
//
// Created on Tue Oct 17 01:36:16 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;
static uint32_t dp[1001][1001];

static void init_dp(uint32_t len1, uint32_t len2)
{
  for (uint32_t i = 0; i < len1; i++) {
    dp[i][0] = 0;
  }
  for (uint32_t i = 0; i < len2; i++) {
    dp[0][i] = 0;
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    string str1, str2;
    cin >> str1;
    cin >> str2;
    init_dp(str1.size(), str2.size());
    for (uint32_t i = 1; i <= str1.size(); i++) {
      for (uint32_t 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;
  }

  return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int n, dp[1024][1024];
	string a, b;
	cin >> n;
	
	while(n)
	{
		n--;
		memset(dp, 0, sizeof(dp));

		cin >> a;
		cin >> b;

		for(int i = 0; i <= a.size(); i++)
		{
			for(int j = 0; j <= b.size(); j++)
			{
				if(a[i+1] == b[j+1])
				{
					dp[i+1][j+1] = dp[i][j] + 1;
				}
				else
				{
					dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
				}
			}
		}

		cout << dp[a.size()][b.size()] << endl;
	}
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)

#define REP(i, n) FOR(i, 0, n)
#define REPE(i, n) for (int i = 0; i <= (n); ++i)

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'

//DP法
template <class T>
inline bool chmin(T &a, T b) //change minimum
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) //change max
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

typedef long long ll; //64bit型
using namespace std;

const long long INF = 1LL << 60; //無限大の値
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;
    Y = ' ' + Y;
    REPE(i, m)
    {
        REPE(j, n)
        {
            C[i][j] = 0;
        }
    }
    FORE(i, 1, m)
    {
        FORE(j, 1, n)
        {
            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]);
        }
    }
    return maxl;
}

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

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

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;
}

int solve(const string &X, const string &Y) {
    const int xlen = (int) X.size();
    const int ylen = (int) Y.size();
    vector<vector<int>> dp(xlen + 1, vector<int>(ylen + 1, 0));

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

    return dp[xlen][ylen];
}

int main(void) {
    int N;
    cin >> N;

    for (int i = 0; i < N; i++) {
        string X, Y;
        cin >> X >> Y;
        cout << solve(X, Y) << endl;
    }

    return 0;
}