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 <string>
#include <algorithm>
#include <vector>

using namespace std;
static const int N = 1000;

int lenCommon(string s1, string s2)
{
	int m = s1.size();
	int n = s2.size();
	int len = max(m, n);
	vector<vector<int> > dp(N+1, vector<int>(N+1, 0));

	//s1 = " " + s1;
	//s2 = " " + s2;

	//for (int i = 0; i <= len; ++i) dp[i][0] = 0;
	//for (int i = 0; i <= len; ++i) dp[0][i] = 0;

	int ret = 0;
	for (int i = 1; i <= m; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			if (s1[i - 1] == s2[j - 1])
				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()
{
	string s1, s2;
	int num; cin >> num;
	for (int i = 0; i < num; ++i)
	{
		cin >> s1 >> s2;
 		int res = lenCommon(s1, s2);
		cout << res << endl;
	}
}

C++: #include<stdio.h>
??
int hantei(char x[], char y[]) {
????int xn = 0, yn = 0, flag = 0, i, j, max = 0;
????int c[1001][1001];
??????
????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 <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
using namespace std;

bool findSubStr(string& shortword, vector<vector<int> >& charMap) {
	int i,j;
	j=0;
	for(i=0; i<(int)shortword.size(); ++i) {
		if(charMap[shortword[i]-'a'].empty()) return false;
		auto itr=charMap[shortword[i]-'a'].begin();
		while(itr!=charMap[shortword[i]-'a'].end()) {
			if(*itr<j) {
				++itr;
			} else {
				break;
			}
		}
		if(itr==charMap[shortword[i]-'a'].end()) return false;
		j=*itr;
	}
	return true;
}

int longestSQ(string& shortword, string& longword) {
	int i,j;
	string tempstr,prestr;
	vector<vector<int> > charMap(26);
	queue<string> targetword;
	map<string,bool> inqueue;
	for(i=0; i<(int)longword.size(); ++i) {
		charMap[longword[i]-'a'].push_back(i);
	}
	targetword.push(shortword);
	while(!targetword.empty()) {
		tempstr=targetword.front();
		if(findSubStr(tempstr,charMap)) return (int)tempstr.size();
		j=(int)tempstr.size();
		for(i=0; i<j; ++i) {
				tempstr=targetword.front();
				if(i==0 || tempstr[i]!=tempstr[i-1]) {
					tempstr.erase(tempstr.begin()+i);
					if(inqueue.find(tempstr)==inqueue.end()) {
						targetword.push(tempstr);
						inqueue[tempstr]=true;
					}
				}
		}
		targetword.pop();
	}
	return 0;
}

int main() {
	int i,q;
	cin >> q;
	string wordA,wordB;
	for(i=0; i<q; ++i) {
		cin >> wordA >> wordB;
		if(wordA.size()<wordB.size()) {
			printf("%d\n",longestSQ(wordA,wordB));
		} else {
			printf("%d\n",longestSQ(wordB,wordA));
		}
	}
	return 0;
}

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

using namespace std;

int lcs(string s1, string s2) {
    s1 = ' ' + s1;
    s2 = ' ' + s2;
    vector<vector<int>> v(s1.length(), vector<int>(s2.length(), 0));

    for (int i = 1; i < s1.length(); ++i) {
        for (int j = 1; j < s2.length(); ++j) {
            if (s1[i] == s2[j])
                v[i][j] = v[i - 1][j - 1] + 1;
            else
                v[i][j] = max(v[i - 1][j], v[i][j - 1]);
        }
    }

    return v[s1.length() - 1][s2.length() - 1];
}

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

    string s1, s2;
    for (int i = 0; i < n; ++i) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << '\n';
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int q;
    int dp[1005][1005];
    dp[0][0]=0;
    cin>>q;
    rep(z,q){
	string a,b;
	cin>>a>>b;
	
	reps(i,a.size()){
	    reps(j,b.size()){
		if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
		else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	    }
	}
	cout<<dp[a.size()][b.size()]<<'\n';
    }
				  
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int q;
  cin>>q;
  string a,b;
  int x[1001][1001];
  x[0][0]=0;
  for(int i=1;i<=1000;i++){
    x[0][i]=0;
    x[i][0]=0;
  }
  for(int i=0;i<q;i++){
    cin>>a>>b;
    for(int j=1;j<=a.size();j++){
      for(int l=1;l<=b.size();l++){
	if(a[j-1]==b[l-1]){
	  if(x[j-1][l-1]+1>x[j][l-1]){
	    x[j][l]=x[j-1][l-1]+1;
	  }else{
	    x[j][l]=x[j][l-1];
	  }
	}else{
	  if(x[j-1][l-1]>x[j][l-1]){
	    x[j][l]=x[j-1][l-1];
	  }else{
	    x[j][l]=x[j][l-1];
	  }
	}
      }
    }
    cout<<x[a.size()][b.size()]<<endl;
  }
  return(0);
}