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>
using namespace std;

static const int N = 1000;

int lcs(string X, string Y) {
    int c[N + 1][N + 1] = {};
    int m = X.length();
    int n = Y.length();

    X = ' ' + X;
    Y = ' ' + Y;
    
    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() {
    int n;
    string X, Y;
    cin >> n;

    for(int i = 0; i < n; i++) {
        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;
    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(int argc, char const *argv[])
{
    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>

using namespace std;

int lcs(string X, string Y) {
  X = ' ' + X;
  Y = ' ' + Y;
  int memo[1010][1010];
  int maxl = 0;

  // 初期化
  for (int i = 0; i < X.size(); i++) memo[i][0] = 0;
  for (int j = 0; j < Y.size(); j++) memo[0][j] = 0;

  for (int i = 1; i < X.size(); i++) {
    for (int j = 1; j < Y.size(); j++) {
      if (X[i] == Y[j]) {
        //cout << "count up!" << endl;
        memo[i][j] = memo[i-1][j-1] + 1;
      } else {
        memo[i][j] = max(memo[i-1][j], memo[i][j-1]);
      }
      maxl = max(maxl, memo[i][j]);
    }
  }
  return maxl;
}

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

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], max = 0, i, j;
  int m = x.size();
  int n = y.size();

  x = ' ' + x;
  y = ' ' + y;
 
  for(i = 1; i <= m; i++) c[i][0] = 0;
  for(i = 1; i <= n; i++) c[0][i] = 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]);
      max = max(max, c[i][j]);
    }
  }
  return max;
}

int main(){
  string x, y;
  int q, i;

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

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

using namespace std;
static const int N = 150;
static const int AX = 1000, AY = 1000;
string  X, Y;

int do_dp(int ax,int ay) {

    int dp[AX][AY];

    for (int i = 0; i < AX; i++) {
        for (int j = 0; j < AY; j++) {
            dp[i][j] = 0;
        }
    }

    for (int i = 0; i < ax; i++) {
        if (X[i] == Y[0]) dp[i][0] = 1;
        if (i > 0) dp[i][0] = max(dp[i][0], dp[i - 1][0]);
    }

    for (int j = 0; j < ay; j++) {
        if (X[0] == Y[j]) dp[0][j] = 1;
        if (j > 0) dp[0][j] = max(dp[0][j], dp[0][j - 1]);
    }

    for (int i = 1; i < ax; i++) {
        for (int j = 1; j < ay; j++) {
            if (X[i] == Y[j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    for(int i = 0;i < ax;i++){
    for(int j = 0;j < ay;j++){
    cout << dp[i][j] << " ";
    }
    cout << '\n';
    }

    return dp[ax - 1][ay - 1];
}

int main() {
    int q;

    cin >> q;

    int A[N];

    for (int i = 0; i < q; i++) {
        cin >> X;
        cin >> Y;
        //cout << X.size() << " " << Y.size() << '\n';
        A[i] = do_dp(X.size(),Y.size());
    }

    for (int i = 0; i < q; i++) {
        cout << A[i] << '\n';
    }

    return 0;
}

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

string x, y;

int lcs(int m, int n);

int main() {
	int i, q, n, m;
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> x >> y;
		cout << lcs(x.length(), y.length()) << endl;
	}
	return 0;
}

int lcs(int m, int n) {
	int i, j, maxl = 0, c[MAX][MAX];
	c[0][0] = 0;
	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 - 1] == y[j - 1])c[i][j] = c[i - 1][j - 1] + 1;
			else c[i][j] = max(c[i][j - 1], c[i - 1][j]);
			maxl = max(maxl, c[i][j]);
		}
	}
	return maxl;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int q; cin >> q;
    rep(i, q) {
        string s, t; cin >> s >> t;
        vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1));

        rep(j, s.size()) {
            rep(k, t.size()) {
                if (s[j] == t[k]) {
                    dp[j+1][k+1] = max(dp[j][k] + 1, dp[j+1][k]);
                    dp[j+1][k+1] = max(dp[j+1][k+1], dp[j][k+1]);
                } else {
                    dp[j+1][k+1] = max(dp[j][k+1], dp[j+1][k]);
                }
            }
        }
        cout << dp[s.size()][t.size()] << endl;
    }
    return 0;
}