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 <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int q;
	cin>>q;
	vector<int> ans(q);
	//vector<char> x,y;
	/*if(q>21){
		x.resize(101);
		y.resize(101);
	}*/
	string x,y;
	vector<vector<int>> a;
	rep(aaa,q){
		cin>>x;
		cin>>y;
		int xs=x.size();
		int ys=y.size();
		a.resize(xs+1);
		rep(i,xs+1){
			a[i].resize(ys+1);
		}
		rep(i,xs+1){
			rep(j,ys+1){
				if(i==0 || j==0){
					a[i][j]=0;
				}else if(x[i-1]==y[j-1]){
					a[i][j]=a[i-1][j-1]+1;
				}else{
					a[i][j]=max(a[i-1][j],a[i][j-1]);
				}
			}
		}
		ans[aaa]=a[xs][ys];
	}
	rep(i,q){
		cout<<ans[i]<<endl;
	}
	

}

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

using namespace std;

/**
 *  lcs(m,n) = 
 *  if x[m] == y[n] lcs[m-1,n-1]+1
 *  max(lcs[m-1,n],lcs[m,n-1])
 *
 */

string x, y;

const int q = 150;

int c[q][q];

int lcs(int m, int n)
{
	if (m == -1 || n== -1) return 0;
	if (x[m] == y[n]) return lcs(m-1,n-1) + 1;
	int & cc = c[m][n];
	if (cc != -1) return cc;
	int xx = lcs(m-1,n);
	int yy = lcs(m,n-1);
	cc = xx > yy ? xx : yy;
	return cc;
}

int main()
{
	int n = 0;
	x.resize(q);
	y.resize(q);
	cin >> n; 
	for (int i=0;i<n;i++)
	{
		cin >> x;
		cin >> y;
		cout << lcs(x.size()-1, y.size()-1) << endl;
		x.clear();
		y.clear();

	memset(c, -1, sizeof(c));
	}
}

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

using namespace std;

string s, t;

vector<vector<int>> memo(2000, vector<int>(2000,-1));

//s???i??????????????§???t???j??????????????§?????£?????¨??????LCS
int solve(int i, int j) {
	if (memo[i][j] != -1)return memo[i][j];

	if (i == 0 && j == 0)return (s[0] == t[0]);
	if (i == 0)return memo[i][j] = (bool)(solve(i, j - 1) + (s[i] == t[j]));
	if (j == 0)return memo[i][j] = (bool)(solve(i - 1, j) + (s[i] == t[j]));
	return memo[i][j] = max(solve(i - 1, j), solve(i, j - 1))+(s[i] == t[j]);
}

int main() {
	int n;
	cin >> n;
	while (n--) {
		cin >> s >> t;
		memo = vector<vector<int>>(2000, vector<int>(2000,-1));
		cout << solve(s.size() - 1, t.size() - 1) << endl;
	}
}

C++: /* ALDS1_10_C: Longest Common Sequence */

#include <iostream>
#include <cstdio>

const int MAX_LENGTH = 1000 + 1;

int max_lcs(char X[], char Y[]) {
    int lcs[MAX_LENGTH + 1][MAX_LENGTH + 1];
    int i, xsize, ysize;

    for(i = 0; X[i]; i++)
        lcs[i][0] = 0;
    xsize = i;

    for(i = 0; Y[i]; i++)
        lcs[0][i] = 0;
    ysize = i;

    for (int ix = 1; ix <= xsize; ix++) {
        for (int iy = 1; iy <= ysize; iy++) {
            if (X[ix - 1] == Y[iy - 1]) {
                lcs[ix][iy] = lcs[ix - 1][iy - 1] + 1;
            }
            else {
                int above = lcs[ix - 1][iy];
                int left  = lcs[ix][iy - 1];
                lcs[ix][iy] = above < left ? left : above;
            }
        }
    }
    return lcs[xsize][ysize];
}

int main() {
    int n_pairs;
    scanf("%d", &n_pairs);

    char X[MAX_LENGTH], Y[MAX_LENGTH];
    for (int i = 0; i < n_pairs; i++) {
        scanf("%s\n%s", X, Y);
        printf("%d\n", max_lcs(X, Y));
    }

    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

short checkTable[1001][1001];

int tmp_max=0;


void calc(int index,char pattern[],char to_search[],int to_search_length){

	for(int i=to_search_length-1;i>=0;i--){
		if(to_search[i]==pattern[index]){
			checkTable[index][i]=1;
			if(pattern[index+1]!='\0' && i < to_search_length-1){
				checkTable[index][i] = checkTable[index+1][i+1] + checkTable[index][i];
			}
		}else{
			if(i != to_search_length-1){
				if(pattern[index+1] != '\0'){
					checkTable[index][i]=(checkTable[index+1][i]>checkTable[index][i+1])
							?checkTable[index+1][i]:checkTable[index][i+1];

				}else{
					checkTable[index][i]=(checkTable[index][i+1]>0)?checkTable[index][i+1]:0;
				}
			}else{
				if(pattern[index+1] != '\0'){
					checkTable[index][i]=(checkTable[index+1][i]>0)?checkTable[index+1][i]:0;
				}else{
					checkTable[index][i] = 0;
				}
			}
		}
		tmp_max = (tmp_max >= checkTable[index][i])?tmp_max:checkTable[index][i];
	}
}

int main(){

	int q,left_length,right_length;
	char left[1001],right[1001];

	scanf("%d",&q);

	for(int i=0;i<q;i++){
		left_length=0;
		right_length=0;
		scanf("%s %s",left,right);
		for(int k=0;left[k]!='\0';k++)left_length++;
		for(int k=0;right[k]!='\0';k++)right_length++;

		if(right_length>=left_length){

			for(int k=left_length-1;k>=0;k--)calc(k,left,right,right_length);
		}else{

			for(int k=right_length-1;k>=0;k--)calc(k,right,left,left_length);
		}
		printf("%d\n",tmp_max);
		tmp_max=0;
	}

    return 0;
}

C++: #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int q, n, m, dp[1007][1007]; string s, t;
int main() {
	cin >> q;
	while(q--) {
		cin >> s >> t;
		n = s.size(), m = t.size();
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				dp[i][j] = (s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]));
			}
		}
		cout << dp[n][m] << endl;
	}
}