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 <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;cin>>q;
  FOR(i,0,q){
    string x, y;
    cin >> x >> y;
    int n = x.length();
    int m = y.length();
    int dp[n+1][m+1];
    CLR(dp);
    FOR(i,0,n){
      FOR(j,0,m){
        if(x[i]==y[j]){
          dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
        }
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
      }
    }
    cout<<dp[n][m]<<endl;
  }
}

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

int main(){
  int n;
  std::string x,y;
  std::cin>>n;
  int a[1001][1001];
  int b[n];

  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<1001;j++){
      for(int k=0;k<1001;k++){
	a[j][k]=0;
      }
    }
    for(int j=1;j<=x.size();j++){
      for(int k=1;k<=y.size();k++){
	if(x[j-1]==y[k-1]){
	  a[j][k]=a[j-1][k-1]+1;
	}else{
	  if(a[j-1][k]>a[j][k-1]){
	    a[j][k]=a[j-1][k];
	  }else{
	    a[j][k]=a[j][k-1];
	  }
	}
      }
    }
    b[i]=a[x.size()][y.size()];
  }

  for(int i=0;i<n;i++){
  std::cout<<b[i]<<"\n";
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;


int lcs(string a, string b) {
	int dp[1009][1009];

	for (int i = 0; i <= a.size(); i++) {
		for (int j = 0; j <= b.size(); j++) {
			if (i == 0 || j == 0) dp[i][j] = 0;
			else if (a[i - 1] == b[j - 1])
				dp[i][j] = max(max(dp[i - 1][j - 1] + 1, dp[i - 1][j]), dp[i][j - 1]);
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	return dp[a.size()][b.size()];
}

int main() {
	int q;
	cin >> q;
	getchar();
	while (q--) {
		string a, b;
		getline(cin, a);
		getline(cin, b);
		/*cout << "=======" << a << "=======" << endl;
		cout << "=======" << b << "=======" << endl;*/
		cout << lcs(a, b) << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{

// }}}

struct FastIO {
    FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); }
} fastIO_ydk ;

void slv()
{
    static int dp[1005][1005];

    string a, b;
    cin >> a >> b;

    dp[0][0] = 0;
    for (int i = 0; i < a.length(); ++i) {
        for (int j = 0; j < b.length(); ++j) {
            if (a[i] == b[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            } else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }

    cout << dp[a.length()][b.length()] << endl;

    return;
}

signed main()
{
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) slv();
    return 0;
}

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

#define MAX 1000

int c[MAX][MAX];

int lcs(string A, string B)  {
    int a = A.length();
    int b = B.length();
    int maxl = 0;

    A = ' ' + A;
    B = ' ' + B;
    //配列を作る
    for(int i=0; i<a; i++) {
        c[i][0] = 0;
    }
    for(int j=0; j<b; j++) {
        c[0][j] = 0;
    }
    for(int i=1; i<=a; i++) {
        for(int j=1; j<=b; j++) {
            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]);
            }
            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;
}

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;
	Y = ' ' + Y;
	for (int i = 1; i <= m; i++)c[i][0] = 0;
	for (int j = 1; 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;
}