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

int lcs(string str1, string str2)
{
	int len[1001][1001] = { 0 };

	int len1 = str1.length();
	int len2 = str2.length();
	str1 = ' ' + str1;
	str2 = ' ' + str2;

	for (int i = 0; i <= len1; i++)
		for (int j = 0; j <= len2; j++) len[i][j] = 0;

	for (int i = 1; i <= len1; i++)
	{
		for (int j = 1; j <= len2; j++)
		{
			if (str1[i] == str2[j]) len[i][j] = len[i - 1][j - 1] + 1;
			else len[i][j] = max(len[i - 1][j], len[i][j - 1]);
		}
	}
	return len[len1][len2];
}

int main()
{
	int n;
	string str1, str2;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> str1 >> str2;
		cout << lcs(str1, str2) << endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int dp[1001][1001] = { 0 };
int main()
{
	int sy,sx, q, k;
	char x[2001], y[2001];
	k = 0;
	scanf("%d", &q);
	for (int z = 0; z < q; z++)
	{
		if (z != 0)
		{
			for (int i = 1; i <= sy; i++)
			{
				for (int j = 1; j <= sx; j++)
					dp[i][j] = 0;
			}
		}
		scanf("%s %s", x, y);
		sx = strlen(x);
		sy = strlen(y);
		for (int i = 1; i <= sy; i++)
		{
			for (int j = 1; j <= sx; j++)
			{
				if (y[i - 1] == x[j - 1])
					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[sy][sx]);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define For(I,A,B) for(int I=(A); I < (B); ++I)
int main()
{
int t;
cin>>t;
while(t--){
int a[1000]={0},b[1000]={0},c[200][200];
int x,y,z,k=0,l,i,j;

 For(i,0,200)
 For(j,0,200)
 c[i][j]=0;


 cin>>x>>y;
 For(i,0,x+1)
 For(j,0,y+1)
 c[i][j]=0;
 For(i,1,x+1) cin>>a[i];
 For(i,1,y+1) cin>>b[i];

 For(i,1,x+1)
 For(j,1,y+1)
 {
     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]);
 }
    cout<<c[x][y]<<endl;

}
}
    return 0;
}

C++: #include<iostream>
#include<string>
int main()
{
  int n;
  int an[1000];
  int l=0;
  std::cin>>n;
  std::string x;
  std::string y;
  int ans[100000][100000];
  int j,k;
  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<1000;j++){
      for(int k=0;k<1000;k++){
	ans[j][k]=0;
      }
    }
    for(int j=0;j<x.size();j++){
      for(int k=0;k<y.size();k++){
	if(x[j]==y[k]){
	  ans[j][k]=ans[j-1][k-1]+1;
	}else{
	  if(ans[j][k-1]>ans[j-1][k]){
	    ans[j][k]=ans[j][k-1];
	  }else{
	    ans[j][k]=ans[j-1][k];
	  }
	}
      }
    }
    std::cout<<ans[x.size()-1][y.size()-1]<<'\n';  
  }
  return 0;
}

C++: #include <iostream>
#include <string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)

int dp[1001][1001];

int main(){
  int a;
  cin >> a;
  rep(i,a) {
  string x,y;

  cin >> x >> y;

  int n = x.size();
  int m = y.size();
  rep(i,n+1) dp[i][0] = 0;
  rep(j,m+1) dp[0][j] = 0;

  rep(i,n) {
    rep(j,m) {
      if(x[i] == y[j]) {
        dp[i + 1][j + 1] = max(dp[i][j] + 1,max(dp[i + 1][j],dp[i][j + 1]));
      } else {
        dp[i + 1][j + 1] = max(dp[i + 1][j],dp[i][j + 1]);
      }
    }
  }

  //rep(i,n+1) {
  //  rep(j,m+1)  {
  //    cout << dp[i][j] << " ";
  //  }
  //  cout << endl;
  //}
  cout << dp[n][m] << endl;
  }

}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stdlib.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    int Q;
    string X, Y;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        cin >> X >> Y;
        int DP[1001][1001];
        memset(DP, 0, sizeof(DP));
        for (int sx = 1; sx <= X.size(); ++sx) {
            for (int sy = 1; sy <= Y.size(); ++sy) {
                DP[sx][sy] = max(DP[sx][sy-1], DP[sx][sy-1]);
                if (X[sx] == Y[sy]) {
                    DP[sx][sy] = max(DP[sx][sy], DP[sx-1][sy-1]+1);
                }
            }
        }
        cout << DP[X.size()][Y.size()] << endl;
    }
    return 0;
}