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 <cstdio>
#include <vector>
#include <queue>
#include <map>
using namespace std;

bool findSubStr(string& shortword, vector<vector<int> >& charMap) {
	int i,j;
	j=0;
	for(i=0; i<(int)shortword.size(); ++i) {
		if(charMap[shortword[i]-'a'].empty()) return false;
		auto itr=charMap[shortword[i]-'a'].begin();
		while(itr!=charMap[shortword[i]-'a'].end()) {
			if(*itr<j) {
				++itr;
			} else {
				break;
			}
		}
		if(itr==charMap[shortword[i]-'a'].end()) return false;
		j=*itr;
	}
	return true;
}

int longestSQ(string& shortword, string& longword) {
	int i,j;
	string tempstr,prestr;
	vector<vector<int> > charMap(26);
	queue<string> targetword;
	map<string,bool> inqueue;
	for(i=0; i<(int)longword.size(); ++i) {
		charMap[longword[i]-'a'].push_back(i);
	}
	targetword.push(shortword);
	while(!targetword.empty()) {
		tempstr=targetword.front();
		if(findSubStr(tempstr,charMap)) return (int)tempstr.size();
		j=(int)tempstr.size();
		for(i=0; i<j; ++i) {
				tempstr=targetword.front();
				if(i==0 || tempstr[i]!=tempstr[i-1]) {
					tempstr.erase(tempstr.begin()+i);
					if(inqueue.find(tempstr)==inqueue.end()) {
						targetword.push(tempstr);
						inqueue[tempstr]=true;
					}
				}
		}
		targetword.pop();
	}
	return 0;
}

int main() {
	int i,q;
	cin >> q;
	string wordA,wordB;
	for(i=0; i<q; ++i) {
		cin >> wordA >> wordB;
		if(wordA.size()<wordB.size()) {
			printf("%d\n",longestSQ(wordA,wordB));
		} else {
			printf("%d\n",longestSQ(wordB,wordA));
		}
	}
	return 0;
}

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

int memo[1001][1001];
string s,t;

int dfs(int i, int j)
{
    if(i == 0 || j == 0) return 0;
    
    if(memo[i][j] != -1)return memo[i][j];
    
    int res = 0;
    
    if(s[i-1] == t[j-1]) res = dfs(i-1, j-1) + 1;
    else {
        res = max(dfs(i - 1, j), dfs(i, j - 1));
    }
    return memo[i][j] = res;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> s >> t;
        fill((int*)memo, (int*)(memo + (int)max(s.size(), t.size()) + 1), -1);
        cout << dfs(s.size(), t.size()) << endl;
    }
}

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

using namespace std;

int lic(string X,string Y) {
	int c[1001][1001];
	int m = X.size();
	int n = Y.size();
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	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]);
			}
		maxl=max(maxl,c[i][j]);
		}
	}
	return maxl;
}

int main() {
	string X, Y;
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> X >> Y;
		cout << lic(X, Y)<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxx = 1010;
int c[maxx][maxx];

int lcs(char s1[],char s2[]) {
	int m = strlen(s1), n = strlen(s2);
	for (int i = 1; i <= m; i++)
		c[i][0] = 0;
	for (int i = 1; i <= n; i++)
		c[0][i] = 0;

	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (s1[i] == s2[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[m][n];
}
int main()
{
	char s1[maxx], s2[maxx];
	int t;
	cin >> t;
	getchar();
	for (int i = 0; i < t; i++) {
		cin.getline(s1,1010);
		cin.getline(s2,1010);
		printf("%d\n", lcs(s1, s2));
	}

	return 0;
}