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 <cstring>
#include <algorithm>
#include <cstdlib>
#include <vector>
using namespace std;

#define max(a, b) ((a) > (b) ? (a) : (b))

const int MAX_N = 1010;
int dp[MAX_N][MAX_N];

int solve(char str1[], char str2[]) {
    memset(dp, 0, sizeof(dp));
    int sz1 = strlen(str1);
    int sz2 = strlen(str2);
    for(int i = 1; i <= sz1; ++i) {
        for(int j = 1; j <= sz2; ++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]);
        }
    }
    return dp[sz1][sz2];
}

int main() {
    int t;
    char str1[MAX_N];
    char str2[MAX_N];
    scanf("%d\n", &t);
    while(t--) {
        gets(str1);
        gets(str2);
        printf("%d\n", solve(str1, str2));  
    }
    return 0;
}

C++: //
// Created by ?????°?????? on 2016/04/21.
//

#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;
    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 = 0; 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(){
    string s1,s2;
    int n;
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> s1 >> s2;
        cout << lcs(s1,s2) << endl;
    }
    return 0;
}

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

long lcs(string x, string y) {
    long m = x.size();
    long n = y.size();
    x = ' ' + x;
    y = ' ' + y;
    long dp[m + 1][n + 1];
    for (long i = 0; i <= m; i++) {
        dp[i][0] = 0;
    }
    for (long i = 0; i <= n; i++) {
        dp[0][i] = 0;
    }

    long lcs_max = 0;
    for (long i = 1; i <= m; i++) {
        for (long j = 1; j <= n; j++) {
            if (x[i] == y[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
            lcs_max = max(lcs_max, dp[i][j]);
        }
    }
    return lcs_max;
}

int main() {
    long q;
    string x, y;
    cin >> q;
    for (long i = 0; i < q; i++) {
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
    return 0;
}

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

int q;
string X,Y;
int L[1000][1000];

int max(int i,int j) {return i > j ? i : j;}

int getL(int i,int j) {
	if(L[i][j] != -1) return L[i][j];

	if(i == 0 || j == 0) return 0;
	if(X[i - 1] == Y[j - 1]) return 1 + getL(i - 1,j - 1);
	return max(getL(i,j - 1),getL(i - 1,j));
}

int main() {

	cin >> q;
	for(int i = 0;i < q;i++) {
		for(int j = 0;j < 1000;j++) {
			for(int k = 0;k < 1000;k++) L[j][k] = -1;
		}
		cin >> X >> Y;
		cout << getL(X.size(),Y.size()) << endl;
	}
}

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

using namespace std;

int q;
int main() {
	cin >> q;
	for (int i = 0; i < q; i++) {
		string x, y;
		cin >> x >> y;
		int m = x.size();
		int n = y.size();
		x = ' ' + x;
		y = ' ' + y;
		int maxl = 0;
		int c[1001][1001] = {};
		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][j - 1], c[i - 1][j]);
				}
			}
		}
		cout << c[m][n] << endl;
	}
	return 0;
}

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


int main(int argc, char *argv[]){
  int n;
  cin >> n;
  for (int r = 0; r < n; r++) {

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