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 <iostream>
#include <string>
#include <climits>
#include <vector>
using namespace std;

string u, v;
vector<vector<int> > memoization;

int lenLCS(int i, int j) {
  int current_max = INT_MIN;
  int attempt;
  if (i == -1)
    return 0;
  if (j == -1)
    return 0;
  if (memoization[i][j] != -1)
    return memoization[i][j];
  if (u[i] == v[j]) {
    attempt = 1 + lenLCS(i-1,j-1);
    if (attempt > current_max)
      current_max = attempt;
  }
  attempt = lenLCS(i-1,j);
  if (attempt > current_max)
    current_max = attempt;
  attempt = lenLCS(i,j-1);
  if (attempt > current_max)
    current_max = attempt;
  memoization[i][j] = current_max;
  return memoization[i][j];
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> v;
    memoization = vector<vector<int> > (u.size(), vector<int> (v.size(), -1));
    cout << lenLCS(u.size()-1, v.size()-1) << endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>

#define M 1001

int n;

char x[M],y[M];
 
void lcs(void){
  int i,j;
  int len_x, len_y,graph[M][M];

  len_x=strlen(x);
  len_y=strlen(y);
  for(i=1;i<M;i++){
    for(j=1;j<M;j++){
      graph[i][j]=0;
    }
  }
  for(i=1;i<=len_x;i++){
    for(j=1;j<=len_y;j++){
      if(x[i-1]==y[j-1]) graph[i][j]=graph[i-1][j-1]+1;

      else{
        if(graph[i-1][j]>=graph[i][j-1]) graph[i][j]=graph[i-1][j];
        else graph[i][j]=graph[i][j-1];
      }
    }
  }
  printf("%d\n",graph[len_x][len_y]);
}
     
int main()
{
  int i;
   
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%s",x);
    scanf("%s",y);
    lcs();
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
  
#define MAX 1000
  
int main(){
  int i,j,m,q,x,y,c[MAX+1][MAX+1];
  char X[MAX],Y[MAX];
  
  scanf("%d",&q);
  
  for(i=0;i<strlen(X);i++)
    c[i][0] = 0;
  for(j=0;j<strlen(Y);j++)
    c[0][j] = 0;
  
  for(m=0;m<q;m++){
    scanf("%s",X);
    scanf("%s",Y);
    x = strlen(X);
    y = strlen(Y);
    for(i=0;i<x;i++)
      c[i][0] = 0;
    for(j=0;j<y;j++)
      c[0][j] = 0;
  
    for(i=1;i<=x;i++){
      for(j=1;j<=y;j++){
    if(X[i-1] == Y[j-1])c[i][j] = c[i-1][j-1] + 1;
    else if(c[i-1][j] >= c[i][j-1])c[i][j] = c[i-1][j];
    else c[i][j] = c[i][j-1];
      }
    }
    printf("%d\n",c[x][y]);
  }
  
  return 0;
}

C++: //Longest Common Subsequence
#include <iostream>
#include <string>

using namespace std;

static const int N = 1000;

int lcs(string X, string Y) {
    int c[N + 1][N + 1] = {};
    int maxl = 0, m = int(X.size()), n = int(Y.size());
    X = X;
    Y = Y;
    for(int i = 0; i < m + 1; i++) c[i][m] = 0;
    for(int j = 0; j < n + 1; j++) c[n][j] = 0;
    for(int i = m - 1; i >= 0; i--) {
        for(int j = n - 1; j >= 0; j--) {
            if(X[i] == Y[j]) c[i][j] = 1 + c[i + 1][j + 1];
            else c[i][j] = max(c[i][j + 1], c[i + 1][j]);
        }
    }
    return c[0][0];

}

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;

ll lcs(string s1, string s2)
{
	int m = len(s1);
	int n = len(s2);
	s1 = ' '+s1;
	s2 = ' '+s2;
	int (*mat)[1001];
	mat = new int[1001][1001];
	REP(i, m)
	{
		mat[i][0] = 0;
	}
	REP(i, n)
	{
		mat[0][i] = 0;
	}
	int maxx = 0;
	FOR(i, 1, m+1)
	{
		FOR(j, 1, n+1)
		{
			if (s1[i] == s2[j])
				mat[i][j] = mat[i-1][j-1] + 1;
			else
				mat[i][j] = max(mat[i][j-1], mat[i-1][j]);
			maxx = max(maxx, mat[i][j]);
		}
	}
	delete[] mat;
	return maxx;
}
int main()
{
	ios::sync_with_stdio(false);

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

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

#define MAX_N 1000
#define MAX_M 1000

void solve();

string s, t;
int dp[MAX_N + 1][MAX_M + 1];

void solve(){
	for(int i = 0; i < s.size(); i++){
		for(int j = 0; j < t.size(); j++){
			if(s[i] == t[j]){
				dp[i + 1][j + 1];
					dp[i + 1][j + 1] = dp[i][j] + 1;
				} else {
					dp[i + 1][j + 1] = max(dp[i][j], dp[i + 1][j]);
				}
			}
		}
		cout << dp[s.size()][t.size()] << endl;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s >> t;
		solve();
	}
　return 0;
}

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