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 <vector>
#include <string>
#include <algorithm>

using namespace std;

// typedef
typedef long long ll;

// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

// repetition
#define FOR(i,m,n) for(ll i = ((ll) m); i < ((ll) n); ++i)
#define REP(i,n) FOR(i,0,n)

int solve(const string& X, const string& Y) {
    int xlen = X.length()+1, ylen = Y.length()+1;
    int* dp = new int[xlen*ylen];
    for(int i = 0; i < xlen; i++) {
        for(int j = 0; j < ylen; j++) {
            if(i == 0 || j == 0) {
                dp[i*ylen+j] = 0;
                continue;
            }
            dp[i*ylen+j] = max(
                dp[(i-1)*ylen+(j-1)] + (X[i-1] == Y[j-1]? 1 : 0),
                max(dp[(i-1)*ylen+j], dp[i*ylen+(j-1)])
            );
        }
    }
    int ret = dp[xlen*ylen - 1];
    delete[] dp;
    return ret;
}

int main() {
    int q; cin >> q;
    REP(i, q) {
        string X, Y;
        cin >> X >> Y;
        cout << solve(X, Y) << endl;
    }
    return 0;
}

/*
Longest Common Subsequence
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp

dp[i][j] = X1...XiとY1...Yjの最長共通部分列
dp[i][j] = 
dp[i-1][j-1] + 1            if Xi == Yj
max(dp[i][j-1], dp[i-1][j], dp[i-1][j-1]) otherwise
*/

C++: #include<algorithm>
#include<iostream>
#include<cstring>
#define rep(i,a) for(int i=0;i<(a);++i)
#define repd(i,a) for(int i=(a);i>=0;--i)
#define clr(a,v) memset((a),(v),sizeof(a))

const int MAX_X = 1000, MAX_Y = 1000;

int q;
std::string X, Y;
int dp[MAX_X+1][MAX_Y+1];

int main()
{
    std::cin >> q;
    while( q-- )
    {
        std::cin >> X >> Y;

        clr( dp, 0 );

        repd( i, X.size()-1 ) repd( j, Y.size()-1 )
        {
            if( X[i] == Y[j] )
                dp[i][j] = dp[i+1][j+1]+1;
            else
                dp[i][j] = std::max( dp[i+1][j], dp[i][j+1] );
        }

        printf( "%d\n", dp[0][0] );
    }

    return 0;
}

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

#define MAX 1000

int lcs(string X, string Y) {
    int c[MAX+1][MAX+1];
    int m = X.size();
    int n = Y.size();
    int i, j;
    int maxlen = 0;
    X = " " + X;
    Y = " " + Y;

    for (i = 1 ; i <= m ; i++ ) c[i][0] = 0;
    for (j = 1 ; j <= n ; j++ ) c[0][j] = 0;

    for(i = 1 ; i <= m ; i++ ) {
        for(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][j-1], c[i-1][j]);
            }
            maxlen = max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}

int main (void) {
    int N, i;
    string x, y;

    cin >> N;

    for(i = 0 ; i < N ; i++) {
        cin >> x;
        cin >> y;
        printf("%d\n", lcs(x,y));
    }

    return 0;
}

C++: // LCSの練習

#include"bits/stdc++.h"
#include <iostream>
#include <vector>


using namespace std;


int main(){
	
	int q;

	cin >> q ;

	vector<int> ans;

	for(int i= 0; i < q; i++){
		
		string x,y;

		cin >> x;
		cin >> y;

		int len_x = (int)x.length();
		int len_y = (int)y.length();

		// int dp[len_x+1][len_y+1];

		vector<vector<int> > dp(len_x + 1, vector<int>(len_y + 1));

		for(int i = 1; i <= len_x; i++){
			for(int j = 1; j <= len_y; j++){
				if(x[i-1] == y[j-1]){
					dp[i][j] = dp[i-1][j-1]+1;
				}
				else{
					dp[i][j] = max(dp[i-1][j], dp[i][j-1]); 
				}
			}
		}

		ans.push_back(dp[len_x][len_y]);
		// cout << dp[len_x][len_y] << endl;

	}

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

	return 0;
}

C++: #include <iostream>

int lcs(std::string x, std::string y)
{
  int m = x.length();
  int n = y.length();
  int cs[m + 1][n + 1];

  for (int i = 1; i < m + 1; ++i)
    cs[i][0] = 0;
  for (int j = 1; j < n + 1; ++j)
    cs[0][j] = 0;

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

  return cs[m][n];
}

int main()
{
  int q;
  std::cin >> q;

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

  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y){
  int c[N+1][N+1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;  // X[0]に空白を挿入
  Y = ' ' + Y;  // X[0]に空白を挿入
  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 s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}