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 <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int q;
char X[1000], Y[1000];
int dp[1001][1001];

int main(void) {

    scanf("%d", &q);

    for (int i = 0; i < q; ++i) {
        scanf("%s %s", X, Y);
        int xlen = strlen(X), ylen = strlen(Y);
        for (int x = 0; x < xlen; ++x) {
            for (int y = 0; y < ylen; ++y) {
                if (X[x] == Y[y]) {
                    dp[x + 1][y + 1] = dp[x][y] + 1;
                }
                else {
                    if (dp[x + 1][y] > dp[x][y + 1]) {
                        dp[x + 1][y + 1] = dp[x + 1][y];
                    }
                    else {
                        dp[x + 1][y + 1] = dp[x][y + 1];
                    }
                }
            }
        }
        printf("%d\n", dp[xlen][ylen]);
//        memset(dp, 0, sizeof(int)*1001*1001);
    }

    return 0;
}

C++: 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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 = 0; 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;  
    }
     
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
    using namespace std;
int lcs(string x,string y){
    int c[1010][1010];
    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(){
    int q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

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


int lcs(string x, string y){
  int m = x.size();
  int n = y.size();

  int c[1001][1001];
  for(int i=0;i<=m;i++) c[i][0] = 0;
  for(int j=0;j<=n;j++) c[0][j] = 0;

  int maxl = 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(){
  int q;
  cin >> q;
  string s1, s2;
  for(int i=0;i<q;i++){
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

static const int N = 1000;

int LCS(string x, string y) {
    int c[N + 1][N + 1];
    int n = x.length();
    int m = y.length();
    int maxl = 0;
    x = ' ' + x;
    y = ' ' + y;

    REP(i, n) c[i][0] = 0;
    REP(i, m) c[0][i] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(x[i] == y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i][j - 1], c[i - 1][j]);
            }
            maxl = max(c[i][j], maxl);
        }
    }

    return maxl;
}

int soraLCS(string x, string y) {
    int n = x.length();
    int m = y.length();
    x = ' ' + x;
    y = ' ' + y;
    int c[N + 1][N + 1];
    REP(i, n) c[i][0] = 0;
    REP(i, m) c[0][i] = 0;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; 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]);
            }
        }
    }
    return c[n][m];
}

int main() {
    int q;
    string X, Y;

    cin >> q;
    REP(i, q) {
        cin >> X >> Y;
        cout << soraLCS(X, Y) << endl;
    }
    return 0;
}

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

using namespace std;
const int MAX_Q = 150, MAX_X = 1000;
int q, dp[MAX_X + 1][MAX_X + 1];
string x[MAX_X], y[MAX_X];

void solve() {
    for (int i = 0; i < q; i++) {
        for (int j = 0; j < x[i].length(); j++) {
            for (int k = 0; k < y[i].length(); k++) {
                if (x[i][j] == y[i][k]) {
                    dp[j + 1][k + 1] = dp[j][k] + 1;
                } else {
                    dp[j + 1][k + 1] = max(dp[j][k + 1], dp[j + 1][k]);
                }
            }
        }
        cout << dp[x[i].length()][y[i].length()] << endl;
    }
}

int main() {
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> x[i] >> y[i];
    }
    solve();
    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++: //Longest Common Subsequence
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int q;
  string X, Y;
  int dp[1001][1001]={};
  int m, n;
  int ans;


  cin >> q;
  REP(s, q){
    dp[1001][1001]={};
    cin >> X >> Y;
    m=X.size();
    n=Y.size();
    REP(i, m){
      REP(j, n){
        if(X[i] == Y[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]);
      }
    }
    cout << dp[m][n] <<endl;
  }


  return 0;
}