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 <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>
#include <climits>

using namespace std;


int lcs(string x, string y) {
    int c[1001][1001];
    int n = x.length();
    int m = y.length();
    for(int i = 0; i < n; i++) {
        c[i][0] = 0;
    }
    for(int j = 0; j < m; j++) {
        c[0][j] = 0;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(x[i-1] == y[j-1]) {
                c[i][j] = c[i-1][j-1] + 1;
            } else {
                c[i][j] = max(c[i][j-1], c[i-1][j]);
            }
        }
    }
    return c[n][m];
}

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

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

std::string x,y;
int lcs[1000][1000];

int max(int k,int l){
  if(k>l){
    return k;
  }else{
    return l;
  }
}

void LCS(int i,int j){
  if(x[i] == y[j]){
    lcs[i][j] = lcs[i-1][j-1]+1;
  }else{
    lcs[i][j] = max(lcs[i-1][j],lcs[i][j-1]);
  }
}

void pre(){
  for(int i=0;i<(int)y.size();i++){
    if(x[0] == y[i]){
      for(int j=i;j<(int)y.size();j++){
	lcs[0][j] = 1;
      }
      break;
    }else{
      lcs[0][i] = 0;
    }
  }

  for(int i=0;i<(int)x.size();i++){
    if(x[i] == y[0]){
      for(int j=i;j<(int)x.size();j++){
	lcs[j][0] = 1;
      }
      break;
    }else{
      lcs[i][0] = 0;
    }
  }

}

int main(){
  int q;
  std::cin >> q;
  for(int k=0;k<q;k++){
    std::cin >> x;
    std::cin >> y;
    int size_x=x.size(),size_y=y.size();
    pre();
    for(int i=1;i<size_x;i++){
      for(int j=1;j<size_y;j++){
	LCS(i,j);
      }
    }

    /*for(int i=0;i<size_x;i++){
      for(int j=0;j<size_y;j++){
	std::cout << lcs[i][j] << ' ';
      }
      std::cout << '\n';
    }
    */
    
    std::cout << lcs[size_x-1][size_y-1] << '\n'; 

  }
  return 0;
}

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


int solve(string x, string y) {
  int lcs[MAX + 1][MAX + 1];
  int xl = x.size();
  int yl = y.size();

  int i, j;
  for (i = 0; i < xl; i++)
    lcs[i][0] = 0;
  for (j = 0; i < yl; j++)
    lcs[0][j] = 0;

  // shift
  x = " " + x;
  y = " " + y;

  int maxlcs = 0;
  for (i = 1; i <= xl; i++) {
    for (j = 1; j <= yl; j++) {
      if (x[i] == y[j]) {
        lcs[i][j] = lcs[i - 1][j - 1] + 1;
      } else {
        int a = lcs[i][j - 1];
        int b = lcs[i - 1][j];
        lcs[i][j] = max(a, b);
      }
      maxlcs = max(maxlcs, lcs[i][j]);
    }
  }
  return maxlcs;
}

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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

int dp[1000][1000];

int main() {
  int q;
  cin >> q;
  REP(loop, q) {
    char S[1000], T[1000];
    cin >> S >> T;

    REP(i, strlen(S)) {
      REP(j, strlen(T)) {
        dp[i][j] = 0;
      }
    }
    for (int i = 0; i < strlen(S); i++) {
      for (int j = 0; j < strlen(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 + 1][j], dp[i][j + 1]);
        }
      }
    }
    cout << dp[strlen(S)][strlen(T)] << endl;
  }

  return 0;
}

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

int main() {
    int q;
    cin >> q;
    for(int i=0; i<q; i++) {
        string A,B;
        cin >> A >> B;
        int aSize = A.size();
        int bSize = B.size();
        int c[aSize+1][bSize+1];
        for(int i=0; i<=aSize; i++) c[i][0] = 0;
        for(int j=0; j<=bSize; j++) c[0][j] = 0;
        for(int i=1; i<=aSize; i++) {
            for(int j=1; j<=bSize; j++) {
                if(A[i-1] == B[j-1]) c[i][j] = c[i-1][j-1] + 1;
                else c[i][j] = max(c[i-1][j], c[i][j-1]);
            }
        }
        cout << c[aSize][bSize] << 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();

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (X[i] == Y[j]) {
        if (i == 0 || j == 0) 
          c[i][j] = 1;
        else 
          c[i][j] = c[i - 1][j - 1] + 1;
      }
      else {
        if (i == 0 || j == 0) 
          c[i][j] = 0;
        else 
          c[i][j] = max(c[i][j - 1], c[i - 1][j]);
      }
    }
  }
  return c[m - 1][n - 1];
}

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