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"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{

// }}}

struct FastIO {
    FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); }
} fastIO_ydk ;

void slv()
{
    static int dp[1005][1005];

    string a, b;
    cin >> a >> b;

    dp[0][0] = 0;
    for (int i = 0; i < a.length(); ++i) {
        for (int j = 0; j < b.length(); ++j) {
            if (a[i] == b[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[a.length()][b.length()] << endl;

    return;
}

signed main()
{
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) slv();
    return 0;
}

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

#define MAX 1000

int c[MAX][MAX];

int lcs(string A, string B)  {
    int a = A.length();
    int b = B.length();
    int maxl = 0;

    A = ' ' + A;
    B = ' ' + B;
    //配列を作る
    for(int i=0; i<a; i++) {
        c[i][0] = 0;
    }
    for(int j=0; j<b; j++) {
        c[0][j] = 0;
    }
    for(int i=1; i<=a; i++) {
        for(int j=1; j<=b; j++) {
            if(A[i]==B[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<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 n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

string LongestCommonSubsequence(string s1, string s2) {
    int N = (int) s1.size();
    int M = (int) s2.size();
    vector < vector < int > > dp(N + 1, vector < int > (M + 1, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (s1[i] == s2[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    string ret;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if(dp[i + 1][j + 1] == ret.size() + 1){
                ret = ret + s2[j];
            }
        }
    }
    return ret;
}

int main() {

    int N; cin >> N;

    REP(i,N) {
        string a,b; cin >> a >> b;
        cout << LongestCommonSubsequence(a,b).size() << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int maxa[1000];
int main(){
  int n;
  int k;
  int count;
  cin>>n;
  char X[1001];
  char Y[1001];
  for(int i=0;i<n;i++){
    cin>>X;
    cin>>Y;
    k=0;
    for(int a=0;X[a]!='\0';a++){
    count=0;
      for(int s=a;X[s]!='\0';s++){
	for(int j=k;Y[j]!='\0';j++){
	  if(X[s]==Y[j]){
	    count++;
	    k=j;
	    break;
	  }
	}
      }
      if(maxa[i]<count)maxa[i]=count;
    }
  }
  for(int i=0;i<n;i++){
    cout<<maxa[i]<<endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#define N 1000
using namespace std;

int lcs(string x, string y){
  int m = x.size();
  int n = y.size();
  int maxsize = 0;
  int c[N + 1][N + 1];

  x = ' ' + x;
  y = ' ' + y;

  for(int i = 1; i < m; i++){
    c[i][0] = 0;
  }

  for(int i = 0; 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];
      }

    maxsize = max(maxsize, c[i][j]);

    }
  }

  return maxsize;
  
}

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

  string x, y;

  for(int i = 0; i < n; i++){
    cin >> x >> y;

    cout << lcs(x, y) << endl;
    
  }

  return 0;

}