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>
using namespace std;

int lcs(string X, string Y) {
	int dp[1000 + 1][1000 + 1];
	int max = 0;

	for (int i = 0; i < X.length(); i++)
		dp[i][0] = 0;

	for (int i = 0; i < Y.length(); i++)
		dp[0][i] = 0;

	for (int i = 1; i < X.length(); i++) {
		for (int j = 1; j < Y.length(); j++) {
			if (X[i] == Y[i])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else if (dp[i - 1][j] >= dp[i][j - 1])
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = dp[i][j - 1];
			max = (max < dp[i][j]) ? dp[i][j] : max;
		}
	}

	return max;
}

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

	for (int i = 0; i < N; i++) {
		string X, Y;
		cin >> X >> Y;

		cout << lcs(X, Y) << endl;
	}

  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
string a,b;
int la,lb;
int dp[10000][10000];

void dpf(void){
	for(int i=1;i<=la;i++){
		for(int j=1;j<=lb;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]);
			}
		}
	}	
	return ;
}
int n;

int main(void){
	cin>>n;
	
	
for(int i=0;i<n;i++){	
	cin>>a>>b;
	la=a.length();
	lb=b.length();
	a=' '+a;
	b=' '+b;
	dpf();
	cout<<dp[la][lb]<<endl;
}


}

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

int main() {
  std::string X;
  std::string Y;
  int q;
  int answers[160];
  std::cin >> q;
  
  for(int p=0; p<q; ++p) {
    std::cin >> X;
    std::cin >> Y;

    int j=0;
    int c=0;

    for(int i=0; i<X.size(); ++i) {
      for(int k=j; k<=i; ++k) {
        if(k >= Y.size()) {
          break;
        }
        if(X[i] == Y[k]) {
          c++;
          j = k+1;
          break;
        }
      }
    }

    answers[p] = c;
  }

  for(int i=0; i<q; ++i) {
    std::cout << answers[i] << std::endl;
  }

}

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

int lcs(string x,string y);

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

int lcs(string x,string y){
	int m = x.size() , n = y.size();
	x = ' '+x; y = ' '+y;
	int **c;
	c = new int*[m+1]; for(int i=0;i<=m;i++) c[i] = new int[n+1];
	for(int i=0;i<=m;i++) c[i][0] = 0; for(int j=0;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]);
			if(i==m&&j==n) return c[i][j];
		}
	}

	for(int i=0;i<=m;i++) delete [] c[i]; delete [] c;
}

C++: #include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

const int kMax = 1000 + 10;

int n, m;
char a_str[kMax], b_str[kMax];
int dp[kMax];

vector<int> init_num() {
    vector<int> res;
    map<char, set<int> > table;
    for(int i = 0;i < n;++ i) {
        if(table.count(a_str[i]) > 0) table[a_str[i]].insert(i);
        else {
            set<int> s;
            s.insert(i);
            table[a_str[i]] = s;
        }
    }
    for(int i = 0;i < m;++ i) {
        if(table.count(b_str[i]) > 0) {
            for(auto it = table[b_str[i]].rbegin();it != table[b_str[i]].rend();++ it) {
                res.push_back(*it);
            }
        }
    }
    return res;
}

int solve() {
    int res = 1;
    n = strlen(a_str);
    m = strlen(b_str);
    vector<int> num = init_num();
    dp[0] = num[0];
    for(int i = 1;i < num.size();++ i) {
        if(dp[res - 1] < num[i]) dp[res ++] = num[i];
        else dp[lower_bound(dp, dp + res, num[i]) - dp] = num[i];
    }
    return res;
}

int main() {
    int q;
    scanf("%d", &q);
    while(q --) {
        scanf("%s%s", a_str, b_str);
        printf("%d\n", solve());
    }
    return 0;
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int dp[1000][1001] = {0};

void dfs(int i, int j, string q, string b){
    int x = j;
    string tar = b.substr(x, 1);
    while(x < b.length() && q != tar){
        x++;
        tar = b.substr(x, 1);
    }
    if(i == 0 && x < b.length()){
        while(x < b.length()){
            x++;
            dp[i][x] = 1;
        }
        return;
    }
    while(x < b.length()){
        x++;
        dp[i][x] = max(dp[i-1][j] + 1, dp[i][x]);
    }
    dp[i][j] = max(dp[i][j], dp[i-1][j]);
    return;
}

int main() {
    int n; cin >> n;
    REP(k, n){
        string a, b;
        cin >> a >> b;
        REP(i, a.length()){
            string q = a.substr(i, 1);
            REP(j, b.length()+1) dfs(i, j, q, b);
        }
        cout << dp[a.length()-1][b.length()] << endl;
    }
    return 0;
}