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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q; cin>>q;
    for(int i=0; i<q; i++){
        string x,y;
        cin>>x>>y;
        int nx=(int)x.size();
        int ny= (int)y.size();
        vector<vector<Int>> dp(nx+1,vector<Int>(ny+1,0));
        for(int i=0; i<(int)x.size(); i++){
            for(int j=0; j<(int)y.size(); j++){
                if(x[i]==y[j]){
                    dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
                }
                dp[i+1][j+1]=max({dp[i+1][j+1],dp[i][j+1],dp[i+1][j]});
            }
        }
        cout<<dp[nx][ny]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <string>
#include <utility>
using namespace std;

int n;
string a,b;


int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a >> b;
		int t[1010][1010] = {};
		for (int i = 0; i < a.length(); i++){
			for (int j = 0; j < b.length(); j++){
				if (i == 0 || j == 0)t[i][j] = 0;
				else if (a[i] == b[i]){
					t[i + 1][j + 1] = t[i][j] + 1;
				}
				else t[i + 1][j + 1] = max(t[i + 1][j], t[i][j + 1]);
			}
		}
		cout << t[a.length()][b.length()] << endl;
	}
	return 0;
}

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

int main() {
  int q;
  cin >> q;
  for (int i=0;i<q;++i) {
    string str1,str2;
    cin >> str1 >> str2;
    int size1 = str1.size();
    int size2 = str2.size();
    int matrix[size1+1][size2+1];
    for (int j=0;j<=size1;++j)
      matrix[j][0] = 0;
    for (int j=0;j<=size2;++j)
      matrix[0][j] = 0;
    for (int j=0;j<=size1;++j) {
      for (int k=0;k<=size2;++k) {
	if (j<=0||k<=0) {
	  matrix[j][k] = 0;
	}
	else if (str1[j]==str2[k]) {
	  matrix[j][k] = 1 + matrix[j-1][k-1];
	}
	else {
	  matrix[j][k] = max(matrix[j][k-1],matrix[j-1][k]);
	}
      }
    }
    cout << matrix[size1][size2] << endl;
  }
}

int max(int a,int b) {
  if (a>b)
    return a;
  else
    return b;
}

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

int main()
{
    int q;
    cin >> q;
    for (int ii = 0; ii < q; ii++)
    {
        string X, Y;
        cin >> X >> Y;
        int x = X.size();
        int y = Y.size();
        int dp[x + 1][y + 1];
        memset(dp, 0, sizeof(dp));
        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < y; j++)
            {
                if (X[i] == Y[j])
                {
                    dp[i + 1][j + 1] = max({dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1]});
                }
                else
                {
                    dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
                }
            }
        }
        cout << dp[x][y] << endl;
    }
}

C++: // Longest Common Subsequence

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
#define MAX 1001

int make_lcs(string x, string y) {
	int lcs[MAX][MAX] = {};
	x = ' ' + x;
	y = ' ' + y;
	for (unsigned int i=0;i<x.length();i++) {
	for (unsigned int j=0;j<y.length();j++) {
	if (i!=0 && j!=0) {
	if (x[i] == y[j]) {
	lcs[i][j] = lcs[i-1][j-1] + 1;
	}
	else {
	lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
	}
	}
	}
	}
	return lcs[x.length()-1][y.length()-1];
}
int main() {
	int n;
	string x,y;
	cin >> n;
	for (int k=0;k<n;k++) {
	cin >> x >> y;
	cout << make_lcs(x,y) << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

int dp[1010][1010] = {};



/*----------------------------------------------------------------*/
signed main(){

    int q;
	cin >> q;
	rep(iii,q){
		string s,t;
		cin >> s >> t;
		int sl = s.size();
		int tl = t.size();
		rep(i,sl)rep(j,tl)dp[i][j] = 0;
		rep(i,sl){
			rep(j,tl){
				if(s[i] == t[j]){
					dp[i+1][j+1] = dp[i][j]+1;
				}else{
					dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
				}
			}
		}
		cout << dp[sl][tl] << endl;
	}
	
	

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://abc088.contest.atcoder.jp/tasks/abc088_d