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++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>

using namespace std;

const char *X, *Y;
int X_length, Y_length;

int table_lcs[1001][1001];

int lcs(int x_begin, int y_begin) {
	int i, j, to;
	int max = 0;
	int v_lcs;
	bool alreadySeenTable[256];
	if (table_lcs[x_begin][y_begin] != -1) {
		return table_lcs[x_begin][y_begin];
	}
	
	for (i = 0; i < 256; i++) {
		alreadySeenTable[i] = false;
	}
	i = x_begin;
	to = Y_length-1;
	while(i <= X_length-1) {
		j = y_begin;
		if (alreadySeenTable[X[i]] == true) {
			i++;
			continue;
		}
		bool found = false;
		while (j <= to) {
			if (X[i] == Y[j]) {
				v_lcs = lcs(i + 1, j + 1) + 1;
				if (v_lcs > max) {
					max = v_lcs;
				}
				found = true;
				break;
			}
			else {
				j++;
			}
		}
		if (found == false) {
			alreadySeenTable[X[i]] = true;
			i++;
		}
		else {
			alreadySeenTable[X[i]] = true;
			i++;
			to = j - 1;
		}
	}
	return table_lcs[x_begin][y_begin] = max;
}

int main() {

	int N;
	cin >> N;
	string stringX, stringY;

	for (int i = 1; i <= N; i++) {
		for (int i = 0; i < 1001; i++) {
			for (int j = 0; j < 1001; j++) {
				table_lcs[i][j] = -1;
			}
		}
		cin >> stringX >> stringY;
		X = stringX.c_str();
		X_length = stringX.size();
		Y = stringY.c_str();
		Y_length = stringY.size();
		printf("%d\n", lcs(0, 0));
	}
	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int dp[11111][11111];

void print(string s, string t) {
   int n = s.size(), m = t.size();
   rep (i, n+1) {
      rep (j, m+1) {
         printf("%2lld ", dp[i][j]);
      }
      puts("");
   }
}

int dist(string s, string t) {
   fill(dp[0], dp[1010], 1 << 28);
   dp[0][0] = 0;
   dp[0][0] = 0;
   int N = s.size(), M = t.size();
   rep (i, N+1) dp[i][0] = i;
   rep (i, M+1) dp[0][i] = i;

   rep (i, N) {
      rep (j, M) {
         dp[i+1][j+1] = min({dp[i][j+1]+2, dp[i+1][j]+2, dp[i][j] + (s[i] != t[j])});
      }
   }

   cout << dp[N][M] << endl;
}

int lcs(string s, string t) {
   for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < t.size(); j++) {
         dp[i+1][j+1] = (s[i] == t[j] ? dp[i][j]+1 : max(dp[i][j+1], dp[i+1][j]));
      }
   }
   return dp[s.size()][t.size()];
}

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

   while (n--) {
      string s, t;
      cin >> s >> t;

      cout << lcs(s, t) << endl;
   }

   return 0;
}

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

int lcs (string x, string y) {
	int m = x.length();
	int n = y.length();
	int maxl = 0;
	vector<vector<int>> c(m + 1, vector<int>(n + 1, 0));

	x = ' ' + x;
	y = ' ' + y;
	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() {
	int q; cin >> q;
	for(int cnt = 0; cnt < q; cnt++){
		string x, y;
		cin >> x >> y;
		cout << lcs(x, y) << 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;
    int i,j;

    X = ' ' + X;
    Y = ' ' + Y;

    for(i=0;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-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;

constexpr int N=1000;

int lcs(string x, string y){
   int m=x.size();
   int n=y.size();
   int c[N+1][N+1];
   
   for(int i=0; i<N; i++)
      for(int j=0; j<N; j++)
         c[i][j]=0;
   int ans=0;
   for(int i=1; i<=m; i++){
      for(int 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]=max(c[i-1][j], c[i][j-1]);
         ans=c[i][j];
      }
   }
   return ans;
}

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

   return 0;
}