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"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, q;
string s, t;

int main() {
    cin >> q;

    REP(i, q) {
        cin >> s >> t;
        int ss = s.size(), st = t.size();
        VVi dp(ss+1, Vi(st+1, 0));
        REP2(i, 1, ss+1) REP2(j, 1, st+1) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = max({dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1]});
            } else {
                dp[i][j] = max({dp[i-1][j-1], dp[i-1][j], dp[i][j-1]});
            }
        }

        std::cout << dp[ss][st] << '\n';
    }

    return 0;
}

C++: #include<string>
#include<iostream>
#include<algorithm>
using namespace std;
static const int N = 1001;
int dp[N][N];
int stl(string a, string b) {
	a = " " + a;
	b = " " + b;
	for (int i = 0; i < a.length(); i++) {
		for (int j = 0; j < b.length(); j++)
			dp[i][j] = 0;
	}
	for (int i = 1; i < a.length(); i++) {
		for (int m = 1; m < b.length(); m++) {
			if (a[i] == b[m]) dp[i][m] = dp[i - 1][m - 1] + 1;
			else dp[i][m] = max(dp[i][m - 1], dp[i - 1][m]);
		}
	}
	return dp[a.length() - 1][b.length() - 1];
}
int main(void) {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string a, b;
		cin >> a >> b;
		cout << stl(a, b)<<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();
	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=ma(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;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int n, w;
vector<vector<int>> dp(10000, vector<int>(10000, -1));
vector<int> vv;
vector<int> wv;

void solve(){
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < w; j++) {
      if(j < wv[i]){
        dp[i][j] = dp[i+1][j];
      }else{
        dp[i][j] = max(dp[i+1][j], dp[i+1][j-wv[i]] + vv[i]);
      }
    }
  }
}

int main(){
  cin >> n >> w;
  for (int i = 0; i < n; i++)
  {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    wv.push_back(tmp1);
    vv.push_back(tmp2);
  }

  solve();
  cout << dp[0][w] << endl;
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;++i){
		string a,b;
		int al,bl;
		cin >> a >> b;
		a = ' ' + a;b = ' ' + b;
 		al = a.length();bl = b.length();
		vector<vector<int> > dp;
		dp.resize(al);
		for(int i=0;i<al;++i){
			dp[i].resize(bl);
		}
		for(int i=0;i<al;++i)dp[i][0] = 0;
		for(int i=0;i<bl;++i)dp[0][i] = 0;
		for(int i=1;i<al;++i){
			for(int j=1;j<bl;++j){
				if(a[i]==b[j])dp[i][j] = dp[i-1][j-1] + 1;
				else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
		cout << dp[al-1][bl-1] << endl;
	}
}

C++: 
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string.h>
#include <stdlib.h>

using namespace std;
typedef unsigned long long ull;
typedef  long long ll;

int lcs(string x, string y) {
	//puts("c");
	vector<vector<int>> c;
	c.resize(1001);
	for (int i = 0; i < c.size(); i++) {
		c[i].resize(1001);
	}
	//puts("b");
	x = ' ' + x;
	y = ' ' + y;
	//puts("a");
	for (int i = 0; i < x.size(); i++) {
		c[i][0] = 0;
	}
	for (int i = 0; i < y.size(); i++) {
		c[0][i] = 0;
	}
	for (int i = 1; i < x.size(); i++) {
		for (int j = 1; j < y.size(); 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]);
			}
		}
	}
	return c[x.size() - 1][y.size() - 1];
	
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		string a,b;
		cin >> a;
		cin >> b;
		cout << lcs(a,b) << endl;
	}
	return 0;

}

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

int lcs(string a,string b){
  int c[1001][1001];
  int m=a.size(),n=b.size();
  int mx=0;
  a=' '+a;
  b=' '+b;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(a[i]==b[j]){
	c[i][j]=c[i-1][j-1]+1;
      }else{
	c[i][j]=max(c[i-1][j],c[i][j-1]);
      }
      mx=max(mx,c[i][j]);
    }
  }
  return mx;
}


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