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>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int lcs(string s1,string s2){
    int m=s1.length();
    int n=s2.length();
    s1=' '+s1;
    s2=' '+s2;
    vector2d(int,c,m+1,n+1,0);
    int maxl=0;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            if(s1[i]==s2[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 s,t;
    codefor{
        in(s,t);
        out(lcs(s,t));
    }
}

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

int lcs(string X, string Y) {
	int dp[1000 + 1][1000 + 1];
	int max = 0;

	for (int i = 0; i < X.length(); i++)
		dp[i][0] = 0;

	for (int i = 0; i < Y.length(); i++)
		dp[0][i] = 0;

	for (int i = 1; i < X.length(); i++) {
		for (int j = 1; j < Y.length(); j++) {
			if (X[i] == Y[i])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else if (dp[i - 1][j] >= dp[i][j - 1])
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = dp[i][j - 1];
			max = max < dp[i][j] ? dp[i][j] : max;
		}
	}

	return max;
}

int main() {
	int N;
	cin >> N;

	for (int i = 0; i < N; i++) {
		string X, Y;
		cin >> X >> Y;

		cout << lcs(X, Y) << endl;
	}

  return 0;
}

C++: #include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int q;
int L[1010][1010];
string s1,s2;

void solve(){
    for(int i=0;i<=s1.size();i++)
        for(int j=0;j<=s2.size();j++){
            if(i<=0||j<=0) L[i][j]=0;
            else if(s1[i-1]==s2[j-1]) L[i][j]=1+L[i-1][j-1];
                else L[i][j]=max(L[i][j-1],L[i-1][j]);
        }
    cout<<L[s1.size()][s2.size()]<<endl;
}
int main(){
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>s1>>s2;
        solve();
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int q;
  cin >> q;
  REP(i, q) {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    int dp[1010][1010] = {};
    REP(i, n) REP(j, m) {
      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[n][m] << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
string x,y;
int q;

int lcs(){
  int c[1002][1002],ans=0;
  int  m=(int)x.size(),n=(int)y.size();
    x=' '+x,y=' '+y;
  for(int i=1;i<=m;i++)c[i][0]=0;
  for(int i=1;i<=n;i++)c[0][i]=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 if(c[i-1][j]>=c[i][j-1])c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
      if(ans<=c[i][j])ans=c[i][j];
    }
  return ans;
}

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

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

int lcs(string X, string Y){
  int c[1001][1001];
  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 = 1;i <= 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;
}