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 <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

    auto solve = [](const string& s, const string& t) {
        const int n = s.length(), m = t.length();
        string s1 = " " + s, t1 = " " + t;

        auto dp = make_v(n + 1, m + 1, 0);
        
        FOR(i, 1, n + 1)FOR(j, 1, m + 1) {
            if (s1[i] == t1[j]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j -  1] + 1);
            }
            dp[i][j] = max(dp[i][j], dp[i][j - 1]);
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        }

        return dp[n][m];
    };

    REP(i, n) {
        string s, t; cin >> s >> t;

        cout << solve(s, t) << endl;
    }

    return 0;
}

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

using namespace std;
static const int N = 150;
static const int AX = 1000, AY = 1000;
string  X, Y;

int do_dp(int ax,int ay) {

    int dp[AX][AY];



    for (int i = 0; i < ax; i++) {
        if (X[i] == Y[0]) dp[i][0] = 1;
        if (i > 0) dp[i][0] = max(dp[i][0], dp[i - 1][0]);
    }

    for (int j = 0; j < ay; j++) {
        if (X[0] == Y[j]) dp[0][j] = 1;
        if (j > 0) dp[0][j] = max(dp[0][j], dp[0][j - 1]);
    }

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

    /*for(int i = 0;i < ax;i++){
    for(int j = 0;j < ay;j++){
    cout << dp[i][j] << " ";
    }
    cout << '\n';
    }*/

    return dp[ax - 1][ay - 1];
}

int main() {
    string str;
    int q;

    cin >> q;

    int A[N];

    for (int i = 0; i < q; i++) {
        cin >> X;
        cin >> Y;
        //cout << X.size() << " " << Y.size() << '\n';
        A[i] = do_dp(X.size(),Y.size());
    }

    for (int i = 0; i < q; i++) {
        cout << A[i] << '\n';
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

string LCS(string s, string t){
    ll ns = s.size();
    ll nt = t.size();
    vector< vector<ll> > dp(ns+1, vector<ll> (nt+1, 0));
    // initilaize
    rep(i, 0, ns){
        if(s[i] == t[0]) dp[i][0] = 1;
    }
    rep(i, 0, nt){
        if(s[0] == t[i]) dp[0][i] = 1;
    }
    // build DP table
    rep(i, 1, ns){
        rep(j, 1, nt){
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i] == t[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
        }
    }
    // make LCS
    string ret;
    ll i = ns-1, j = nt-1;
    while(i >= 0 && j >= 0){
        if(s[i] == t[j]){
            ret.push_back(s[i]);
            i--; j--;
        }else{
            if(j == 0) i--;
            else if(i == 0) j--;
            else if(dp[i-1][j] > dp[i][j-1]) i--;
            else j--;
        }
    }
    return ret;
}

int main(){
    ll Q;
    cin >> Q;
    rep(q, 0, Q){
        string x, y;
        cin >> x >> y;
        cout << LCS(x, y).size() << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <memory>
#include <string>
#include <map>
using namespace std;
#define MAX 1003

char A[MAX];
char B[MAX];

void print(){}
int DP[MAX][MAX];
int dp(int i,int j){
    if(i==0||j==0) return 0;
    if(DP[i][j]!=-1) return DP[i][j];
    if(A[i]==B[j]) return DP[i][j]=dp(i-1,j-1)+1;
    return DP[i][j]=max(dp(i,j-1),dp(i-1,j));
}
void solve(){
    memset(DP,-1,sizeof(DP));

    int tmp;
        scanf("%d",&tmp);
        while(tmp--){
                memset(DP,-1,sizeof(DP));
                scanf("%s%s",A,B);
            printf("%d\n",dp(strlen(A),strlen(B)));
        }

}

int main(){

  //  freopen("in","r",stdin);
    solve();
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
 
#define N 1000
 
char A[N+1],B[N+1];
  

  
int Max(int a,int b){
  if(a>=b) return a;
  else return b;
}
int main(){
  int k,a,i,j,m,n,max,c[N+1][N+1];
  scanf("%d",&a);
  for(k=0;k<a;k++){
    scanf("%s",A);
    scanf("%s",B);
    max=0;
     m=strlen(A);
  n=strlen(B);
  for(i=1;i<=m;i++) c[i][0]=0;
  for(j=1;j<=n;j++) c[0][j]=0;
  
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(A[i-1]==B[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];
      max=Max(max,c[i][j]);
    }
  }
    printf("%d\n",max);
  }
  
  return 0;
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 1000;
char s[N+1], t[N+1];
int ls, lt;
int q;
int dp[N+1][N+1];
//dp[i][j] = s[0]...s[i+1]??¨t[0]...t[j+1]???LCS
//(1<=i<=ls, 1<=j<=lt)

int main() {
  int i, j, k;
  scanf("%d ", &q);
  for (k=0; k<q; k++) {
    ls = lt = 0;
    memset(s, 0, sizeof(s)), scanf("%s ", s);
    memset(t, 0, sizeof(t)), scanf("%s ", t);
    while (s[ls]) ls++;
    while (t[lt]) lt++;

    memset(dp, 0, sizeof(dp));
    for (i=1; i<=ls; i++)
      for (j=1; j<=lt; j++) {
        if (s[i]==t[j])
          dp[i][j] = dp[i-1][j-1] + 1;
        else
          dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      }

    printf("%d\n", dp[ls][lt]);
  }

  return 0;
}