Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	results := []int{}
	for i := 0; i < n; i++ {
		results = append(results, resolveInstance())
	}
	for _, v := range results {
		fmt.Println(v)
	}
	return
}

func resolveInstance() int {
	x, y := scanString(sc), scanString(sc)
	lx, ly := len(x), len(y)
	dp := make([][]int, lx+1)
	dp[0] = make([]int, ly+1)
	for i := 1; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
		dp[i][0] = dp[i-1][0]
		for j := 1; j <= ly; j++ {
			dp[i][j] = dp[i-1][j]
			if dp[i][j] < dp[i][j-1] {
				dp[i][j] = dp[i][j-1]
			}
			if x[i-1] == y[j-1] {
				cL := dp[i-1][j-1] + 1
				if dp[i][j] < cL {
					dp[i][j] = cL
				}
			}
		}
	}
	return dp[lx][ly]
}

const (
	remove = 0 + iota
	match
)

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#define MAX 10000


int lcs(std::string X, std::string Y) {
    int c[MAX][MAX];
    int maxl = 0;
    int m = X.size();
    int n = Y.size();
    for (int i = 1; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int i = 1; i <= n; i++) {
        c[0][i] = 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] = std::max(c[i-1][j], c[i][j-1]);
            }
            maxl = std::max(maxl, c[i][j]);
        }
    }
    return maxl;
}

int main() {
    std::string s1, s2;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        std::cin >> s1 >> s2;
        int a = lcs(s1, s2);
        printf("%d\n", lcs(s1, s2));
    }
    
    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 = 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;
}

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

int LCS() {
    int i, j, maxl;
    string X, Y;
    int C[MAX+1][MAX+1];

    cin >> X >> Y;
    size_t X_len = X.length();
    size_t Y_len = Y.length();

    for (i=0; i<=X_len; i++) {
        for (j=0; j<=Y_len; j++) {
            if (i==0 || j==0) C[i][j]=0;
            else {
                if (X[i]==Y[j]) {
                    C[i][j]=C[i-1][j-1]+1;
                    maxl = max(C[i][j], maxl);
                } else C[i][j]=max(C[i-1][j], C[i][j]);
            }
        }
    }

    return maxl;
}

int main() {
    int n, i;
    
    cin >> n;
    for (i=0; i<n; i++) {
        cout << LCS() << 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++){
    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(mxl, 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 << lcs8s1, s2) << endl;
  }
  return 0;
}

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

string X;
string Y;

int calc(int x, int y){
    if (X[x] == '\0') return 0;
    int unuse_ret = calc(x + 1, y);
    int use_ret = 0;
    int y_next = Y.find(X[x], y);
    if (y_next == string::npos) {
        use_ret = 0;
    } else {
        use_ret = calc(x + 1, y_next + 1) + 1;
    }
    return max(unuse_ret, use_ret);
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> X;
        cin >> Y;
        cout << calc(0, 0) << endl;
    }

    return 0;
}