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<cstdio>
#include<iostream>
#include<vector>
using namespace std;

int lcs(string a,string b){
    if(a.size()==0 || b.size()==0) return 0;
    int alen = a.size();
    int blen = b.size();
    vector<vector<int>> dp(alen,vector<int>(blen,0));
    dp[0][0] = a[0] == b[0]? 1:0;
    for(int j = 1; j<blen;j++) dp[0][j] = a[0]==b[j]? 1:dp[0][j-1];
    for(int i = 1; i<alen;i++) dp[i][0] = a[i]==b[0]? 1:dp[i-1][0];
    for(int i = 1;i<alen;i++){
        for(int j=1;j<blen;j++){
            dp[i][j] = dp[i-1][j-1];
            if(a[i]==b[j]) dp[i][j]++;
            dp[i][j] = max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
        }
    }
    return dp[alen-1][blen-1];
}

int main(){
    //string a = "a";
    //string b = "c";
    int p;
    cin >> p;
    for(int i = 0;i<p;i++){
        string a,b;
        cin >> a >> b;
        cout << lcs(a,b) << 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=0; 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;
    }
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
typedef long long ll;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;


string x, y;
ll c[1005][1005];

ll lcs(ll m, ll n) {
	ll maxv = 0;
	for (int i = 0; i <m; ++i) {
		for (int j = 0; j <n; ++j) {
			if (x[i] == y[j])c[i+1][j+1] = c[i][j] + 1;
			else c[i+1][j+1] = max(c[i][j+1], c[i+1][j]);
			maxv = max(maxv, c[i+1][j+1]);
		}
	}
	return maxv;
}

int main() {
	int q;
	cin >> q;
	vector<ll>ans(q);
	repp(i, 0, q) {
		cin >> x >> y;
		ll m = x.size(), n = y.size();
		memset(c, 0, sizeof(c));
		ans[i] = lcs(m, n);
	}
	for (int i = 0; i < q;++i)cout << ans[i] << 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][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<stdio.h>

int hantei(char x[], char y[]) {
  int xn = 0, yn = 0, flag = 0, i, j, max = 0;
  int c[101][101];
  
  while (flag == 0)
  {
    if (x[xn] == '\0')
    {
      xn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  flag = 0;
  
  while (flag == 0)
  {
    if (y[yn] == '\0')
    {
      yn++;
    }
    else
    {
      flag = 1;
    }
  }
  for (i = 1; i < xn + 1; i++) c[i][0] = 0;
  for (j = 1; j < yn + 1; j++) c[0][j] = 0;
  
  for (i = 1; i < xn + 1; i++)
  {
    for (j = 1; j < yn + 1; j++)
    {
      if (x[i - 1] == y[j - 1])
      {
        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 (max < c[i][j]) max = c[i][j];
    }
  }
  
  return max;
}

int main(void) {
  char x[1000], y[1000];
  int q, i;
  
  scanf("%d", &q);
  
  for (i = 0; i < q; i++)
  {
    scanf("%s", x);
    scanf("%s", y);
    printf("%d\n", hantei(x, y));
  }
  
  return 0;
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 1000;
char s[N+1], t[N+1];
int ls, lt;
int q;
int dp[N+1][N+1];
//dp[i][j] = s[0]...s[i+1]??¨t[0]...t[j+1]???LCS
//(1<=i<=ls, 1<=j<=lt)

int main() {
  int i, j, k;
  scanf("%d ", &q);
  for (k=0; k<q; k++) {
    ls = lt = 0;
    memset(s, 0, sizeof(s)), scanf("%s ", s);
    memset(t, 0, sizeof(t)), scanf("%s ", t);
    while (s[ls]) ls++;
    while (t[lt]) lt++;

    memset(dp, 0, sizeof(dp));
    for (i=1; i<=ls; i++)
      for (j=1; j<=lt; j++) {
        if (s[i]==t[j])
          dp[i][j] = dp[i-1][j-1] + 1;
        else
          dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      }

    printf("%d\n", dp[ls][lt]);
  }

  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 = 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;
}