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 <vector>
#include <array>
#include <map>
#include <iterator>
#include <algorithm>

#define X first
#define Y second

using namespace std;

int q;
vector<pair<string,string>> dataset;

int ans(pair<string, string> &data)
{
    array<array<int,1001>,1001> dp = {};
    for (unsigned int i=1; i<=data.X.length(); ++i) {
        for (unsigned int j=1; j<=data.Y.length(); ++j) {
            if (data.X[i-1] == data.Y[j-1]) dp[i][j] = max({dp[i-1][j-1] + 1, dp[i-1][j], dp[i][j-1]});
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    return dp[data.X.length()][data.Y.length()];
}

int main(int argc, char **argv)
{
    cin >> q;
    for (int i=0; i<q; ++i) {
        dataset.emplace_back(std::make_pair("",""));
        cin >> dataset[i].X;
        cin >> dataset[i].Y;
    }
    for (int i=0; i<q; ++i) {
        cout << ans(dataset[i]) << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    string x, y;
    cin >> x >> y;
    int m = x.length();
    int n = y.length();
    vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= n; 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]);
        }
      }
    }
    int ret = dp[m][n];
    cout << ret << '\n';
  }
  return 0;
}

C++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

constexpr auto no_value = numeric_limits<uint64_t>::max();

// str1 should be shorter
int solve(const string& str1, const string& str2) {
  vector<int> cur(str2.size(), 0);
  vector<int> prev;
  int max_ = 0;
  for (auto it = str1.begin(); it != str1.end(); ++it) {
    prev = cur;
    for (size_t i = 0; i < str2.size(); ++i) {
      if (*it == str2[i]) {
        auto p = i == 0 ? 0 : prev[i - 1];
        cur[i] = p + 1;
        max_ = max(max_, cur[i]);
      }
    }
  }
  return max_;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string str1;
    string str2;
    cin >> str1 >> str2;
    auto res = (str1.size() <= str2.size()) ? solve(str1, str2) : solve(str2, str1);
    cout << res << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int q;
string x, y;
int m, n;
int a[1000][1000];
int main()
{
	cin >> q;
	for(int i=0; i<q; i++)
	{
		cin >> x >> y;
		m=x.size();
		n=y.size();
		if(x[0]==y[0])
		{
			a[0][0]=1;
		}
		else
		{
			a[0][0]=0;
		}
		for(int j=1; j<m+n-1; j++)
		{
			if((j<n)&&((x[0]!=y[j])&&(a[0][j-1]==0)))
			{
				a[0][j]=0;
			}
			else if(j<n)
			{
				a[0][j]=1;
			}
			if((j<m)&&((x[j]!=y[0])&&(a[j-1][0]==0)))
			{
				a[j][0]=0;
			}
			else if(j<m)
			{
				a[j][0]=1;
			}
			for(int k=max(1, j-n+1); k<min(j, m); k++)
			{
				if(x[k]==y[j-k])
				{
					a[k][j-k]=a[k-1][j-k-1]+1;
				}
				else
				{
					a[k][j-k]=max(a[k-1][j-k], a[k][j-k-1]);
				}
			}
		}
		cout << a[m-1][n-1] << 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 i,j;
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
 
  for(i=1;i<=m;i++) c[i][0]=0;
  for(j=1;j<=n;j++) c[0]c[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 <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)

#define MAX 1000
int lcs(string x, string y){
    //最長共通部分列問題
    int dp[MAX+1][MAX+1];
    int ret = 0;
    int n = x.size();
    int m = y.size();
    x = ' ' + x; //x[0]をつくる
    y = ' ' + y; //y[0]をつくる

    rep(i, n) dp[i][0] = 0;
    rep(j, m) dp[0][j] = 0;
    
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; 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]);
            }
            ret = max(ret, dp[i][j]);
        }
    }
    return ret;
}

int main() {

    int n;
    cin >> n;

    rep(i, n){
        string s1, s2;
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << 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;//??¨X[0]????????\?????????
	Y=' '+Y;//??¨Y[0]????????\?????????
	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()
{
	string s1,s2;
	int n;cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s1>>s2;
		int ans=lcs(s1,s2);
		if(ans<=20)cout<<ans<<endl;
		else cout<<"20"<<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() {
  string s1, s2;
  int q;
  cin >> q;

  for ( int i = 0; i < q; i++ ) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }

  return 0;
}