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 <cstdlib>
#include<list>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<stack>
#define MAX 1001
using namespace std;
int main() {
	int n; cin >> n;
	string x, y; int data[MAX][MAX] = {0,0};
	for (int d = 0; d <n; d++)
	{
		cin >> x >> y;
		for (int i = 0; i < y.size(); i++)
		{
			for (int j = 0; j < x.size(); j++)
			{
				if (y[i] == x[j]) {
					data[j + 1][i + 1] = data[j][i] + 1;
				}
				else {
					data[j + 1][i + 1] = max(data[j + 1][i], data[j][i + 1]);
				}
			}
		}
		cout << data[x.size()][y.size()]<<endl;
	}
	
	return 0;
}

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

string s, t;
int dp[1001][1001];
int main()
{
    int p;
    cin >> p;
    while(p>0)
    {
        p--;
        cin >> s >> t;
        int n = s.size();
        int m = t.size();
        for (int i = 1; i <= n; i++)
            dp[i][0] = 0;
        for (int i = 1; i <= m; i++)
            dp[0][i] = 0;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if (s[i - 1] == t[j - 1]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }
                else if (dp[i - 1][j] >= dp[i][j - 1]) {
                    dp[i][j] = dp[i - 1][j];
                }
                else {
                    dp[i][j] = dp[i][j - 1];
                }
            }
        }
        cout << dp[n][m] << endl;
    }

}

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

#define MAX 1024

int LCS[MAX][MAX];

int solve(string s1,string s2){
  if(s1.length() > s2.length())
	swap(s1,s2);
  for(int i=1;i<=s1.length();i++){
    for(int j=1;j<=s2.length();j++){
      if(s1[i-1]==s2[j-1])
	LCS[i][j]=LCS[i-1][j-1]+1;
      else
	LCS[i][j]=max(LCS[i][j-1],LCS[i-1][j]);
    }
  }
  return LCS[s1.length()][s2.length()];
}


int main(){
  string s1, s2;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int i=0;i<MAX;i++){
      for(int j=0;j<MAX;j++){
        LCS[i][j] = 0;
      }
    }
    cin>>s1>>s2;
    cout<<solve(s1,s2)<<endl;
    /*
    for(int i=0;i<=s1.length();i++){
      for(int j=0;j<=s2.length();j++){
	cout << LCS[i][j] << "  " ;
      }
      cout << endl;
    }*/
  }

}

C++: #include <iostream>
#include <vector>
#define eol '\n'
using namespace std;

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

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

    int m,n;
    m = x.length();
    n = y.length();

    vector< vector<int> > mat(m+1, vector<int>(n+1,0));

    for (int sum = 2; sum <= m+n; sum++) {
      for (int j = 1; j <= min(sum-1,m); j++) {
        int k = sum - j;

        int plus = x[j-1] == y[k-1] ? 1 : 0;
        mat[j][k] = max(max(mat[j-1][k], mat[j][k-1]), mat[j-1][k-1] + plus);
      }
    }

    cout << mat[m][n] << eol;
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

int main()
{
    cin >> n;
    ll ma = 0;
    REP(i, n)
    {
        string t;
        cin >> s >> t;
        ll c[100][100] = { 0 };
        ma = 0;
        s = ' ' + s; //????????????????????????
        t = ' ' + t;
        FOR(i, 1, s.size())
        {
            c[i][0] = 0;
        }
        FOR(i, 1, t.size())
        {
            c[0][i] = 0;
        }
        FOR(i, 1, s.size())
        {
            FOR(j, 1, t.size())
            {
                if (s[i] == t[j]) {
                    c[i][j] = c[i - 1][j - 1] + 1;
                } else {
                    c[i][j] = max(c[i - 1][j], c[i][j - 1]);
                }
                ma = max(ma, c[i][j]);
            }
        }
        cout << ma << Endl;
    }
}

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

using namespace std;

static const int N = 1000;

int lcs(string X, string Y) {
  int m = X.size(), n = Y.size();
  vector<vector<int>> C(N + 1, vector<int>(N + 1, 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;

  int maxl = 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(void) {
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    string x, y; cin >> x >> y;
    cout << lcs(x, y) << endl;
  }
}