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<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


ll MOD = 1000000007;


int f(string x, string y) {
	vector<vector<int>> dp(x.size() + 1);
	rep(i, x.size() + 1) {
		dp[i].resize(y.size() + 1);
		rep(j, y.size() + 1) dp[i][j] = 0;
	}
	repi(i, 1, x.size() + 1) {
		repi(j, 1, y.size() + 1) {
			if (x[i - 1] == y[j - 1]) {
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else {
				dp[i][j] = max(dp[i][j - 1], max(dp[i - 1][j], dp[i - 1][j - 1]));
			}
		}
	}
	return dp.back().back();
}


int main() {
	int N;
	cin >> N;
	vector<pair<string, string>> s;
	rep(i,N){
		string a, b;
		cin >> a >> b;
		s.push_back(pair<string, string>(a, b));
	}
	rep(i, N) cout << f(s[i].first, s[i].second) << endl;
	return 0;
}

C++: #include <bits/stdc++.h>
#include <tuple>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int dp[1000][1001] = {0};

void dfs(int i, int j, string q, string b){
    int x = j;
    string tar = b.substr(x, 1);
    while(x < b.length() && q != tar){
        x++;
        tar = b.substr(x, 1);
    }
    if(i == 0 && x < b.length()){
        while(x < b.length()){
            x++;
            dp[i][x] = 1;
        }
        return;
    }
    while(x < b.length()){
        x++;
        dp[i][x] = max(dp[i-1][j] + 1, dp[i][x]);
    }
    dp[i][j] = max(dp[i][j], dp[i-1][j]);
    return;
}

int main() {
    int n; cin >> n;
    REP(k, n){
        REP(i, 1000) REP(j, 1001) dp[i][j] = 0;
        string a, b;
        cin >> a >> b;
        REP(i, a.length()){
            string q = a.substr(i, 1);
            REP(j, b.length()+1) dfs(i, j, q, b);
        }
        cout << dp[a.length()-1][b.length()] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <array>
#include <string>
using namespace std;
int q;
int main() {
  cin >> q;
  for (int i = 0; i < q; i++) {
    string x, y;
    cin >> x >> y;
    int L[(int)x.length() + 1][(int)y.length() + 1];
    for (int a = 0; a <= x.length(); a++) {
      for (int b = 0; b <= y.length(); b++) {
        if (a <= 0 || b <= 0) {
          L[a][b] = 0;
        } else if (x[a - 1] == y[b - 1]) {
          L[a][b] = L[a - 1][b - 1] + 1;
        } else {
          L[a][b] = max(L[a - 1][b], L[a][b - 1]);
        }
      }
    }
    cout << L[(int)x.length()][(int)y.length()] << endl;
  }
}

C++: #include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void solve() {
		IOS;
		int q;
		cin >> q;
		REP(loop, q) {
			string x, y;
			cin >> x >> y;
			int m = x.size(), n = y.size();
			vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
			REP(i, m) {
				REP(j, n) {
					dp[i + 1][j + 1] = max({ dp[i + 1][j],dp[i][j + 1],dp[i][j] + (x[i] == y[j]) });
				}
			}
			put(dp[m][n]);
		}
	}
} // namespace idaten

int main() {
	idaten::solve();
	return 0;
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

const int MAX_L=1001;//?????????????????§??????

vector<vector<int> > DP(MAX_L, vector<int>(MAX_L, -1));
string A;//?????????????????????????????????
string B;

//A???a???????????¨????????\??????B???b???????????¨????????\??????????????§????????§?????¨????????????????????????????????????
//m?????????????????????????????±??????????????????
int dev(int a, int b){
	if(DP[a][b]<0){
		int maxi= 0;
		//???????????????????????§??????
		for(int c='A'; c<='Z'; ++c){
			int posa = A.find(c,a);
			int posb = B.find(c,b);
			if(posa>=0 && posb>=0){
				int tmp = dev(posa+1,posb+1);
				maxi = max(maxi, tmp+1);
			}
		}
		DP[a][b]=maxi;
	}
	return DP[a][b];
}

int main(){
	int q;
	cin >> q;
	vector<int> ans(q);
	REP(i,q){
		REP(k,MAX_L){
			REP(l,MAX_L){
				DP[k][l] = -1;
			}
		}
		cin>>A>>B;
		ans[i]=dev(0,0);
	}
	REP(i,q){
		cout<<ans[i]<<endl;
	}
	return 0;
}