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<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_LEN 1000
// 無効な値の定義
const int INV = -1;

int longestCommonSubstring(string a, string b);

int main(void)
{

    int q, len;
    string first_str, second_str;

    cin >> q;

    for(int i = 0; i < q; i++)
    {
        cin >> first_str;
        cin >> second_str;

        len = longestCommonSubstring(first_str, second_str);
        printf("%d\n", len);
    }



    return 0;
}

// 最長共通部分列を算出する関数
int longestCommonSubstring(string str_a, string str_b)

{
    int dp[MAX_LEN + 1][MAX_LEN + 1];
    int a_len, b_len;

    a_len = str_a.size();
    b_len = str_b.size();

    // 文字列の先頭に空白を挿入する
    str_a = " " + str_a;
    str_b = " " + str_b;

    for(int i = 0; i <= a_len; i++)
    {
        dp[i][0] = 0;
    }

    for(int j = 0; j <= b_len; j++)
    {
        dp[0][j] = 0;
    }

    // 最長共通部分列の算出
    for(int i = 1; i <= a_len; i++)
    {
        for(int j = 1; j <= b_len; j++)
        {
            if( str_a[i] == str_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 dp[a_len][b_len];
}

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

using namespace std;

void
chmax(int& aa, int bb)
{
  if (aa < bb) {
    aa = bb;
  }
}

int
main()
{
  int   qq;

  cin >> qq;

  
  for (int qi = 0; qi < qq; qi++) {
    string      xx;
    string      yy;
    vector<vector<int> > dp;

    cin >> xx;
    cin >> yy;

//    cout << xx << endl;
//    cout << xx.length() << endl;

    dp.assign(xx.length() + 1, vector<int>(yy.length() + 1, 0));

    for (int xi = 0; xi < xx.length(); ++xi) {
      for (int yi = 0; yi < yy.length(); ++yi) {
        //cout << yi << endl;
        if (xx[xi] == yy[yi]) {
          dp[xi + 1][yi + 1] = dp[xi][yi] + 1;
        }
        chmax(dp[xi + 1][yi + 1], dp[xi][yi + 1]);
        chmax(dp[xi + 1][yi + 1], dp[xi + 1][yi]);
      }
    }
    cout << dp.back().back() << endl;
  }
}

C++: #include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int n;
int dp[1001][1001];

int main() {
  cin >> n;
  rep(i, n) {
    string x, y;
    cin >> x >> y;
    dp[0][0] = 0;
    rep(i, y.size()) {
      dp[0][i+1] = 0;
    }
    rep(i, y.size()) {
      dp[i+1][0] = 0;
    }
    rep(i, x.size()) {
      rep(j, y.size()) {
        dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        if(x[i] == y[j]) {
          dp[i+1][j+1] = dp[i][j] + 1;
        }
      }
    }
    cout << dp[x.size()][y.size()] << endl;
  }


  return 0;
}

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

using namespace std;

int lcs(string x,string y){
    int m = x.size();
    int n = y.size();
    int lcs_lst[m+1][n+1];
    x = ' '+x;
    y = ' '+y;
    for(int i=0;i<=m;i++) lcs_lst[i][0] = 0;
    for(int i=1;i<=n;i++) lcs_lst[0][i] = 0;

    int ans = 0;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(x[i] == y[j])
                lcs_lst[i][j] = lcs_lst[i-1][j-1]+1;
            else{
                lcs_lst[i][j] = max(lcs_lst[i][j-1],lcs_lst[i-1][j]);
            }
            ans = max(ans,lcs_lst[i][j]);

        }
    }

    return ans;
}

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