Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	for q := ReadInt(); q > 0; q-- {
		x, y := ReadString(), ReadString()
		fmt.Println(LCS(x, y))
	}
}

func LCS(x, y string) int {
	dp := make([][]int, len(x)+1)
	for i := 0; i < len(x)+1; i++ {
		dp[i] = make([]int, len(y)+1)
	}
	for i := 0; i < len(x); i++ {
		for j := 0; j < len(y); j++ {
			dp[i+1][j+1] = Max(dp[i+1][j], dp[i][j+1])
			if x[i] == y[j] {
				dp[i+1][j+1] = Max(dp[i+1][j+1], dp[i][j]+1)
			}
		}
	}
	return dp[len(x)][len(y)]
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
??
using namespace std;
??
short checkTable[1001][1001];
??
int tmp_max=0;
??
??
void calc(int index,char pattern[],char to_search[],int to_search_length){
??
????????for(int i=to_search_length-1;i>=0;i--){
????????????????if(to_search[i]==pattern[index]){
????????????????????????checkTable[index][i]=1;
????????????????????????if(pattern[index+1]!='\0' && i < to_search_length-1){
????????????????????????????????checkTable[index][i] = checkTable[index+1][i+1] + checkTable[index][i];
????????????????????????}
????????????????}else{
????????????????????????if(i != to_search_length-1){
????????????????????????????????if(pattern[index+1] != '\0'){
????????????????????????????????????????checkTable[index][i]=(checkTable[index+1][i]>checkTable[index][i+1])
?????????????????????????????????????????????????????????checkTable[index+1][i]:checkTable[index][i+1];
??
????????????????????????????????}else{
????????????????????????????????????????checkTable[index][i]=(checkTable[index][i+1]>0)?checkTable[index][i+1]:0;
????????????????????????????????}
????????????????????????}else{
????????????????????????????????if(pattern[index+1] != '\0'){
????????????????????????????????????????checkTable[index][i]=(checkTable[index+1][i]>0)?checkTable[index+1][i]:0;
????????????????????????????????}else{
????????????????????????????????????????checkTable[index][i] = 0;
????????????????????????????????}
????????????????????????}
????????????????}
????????????????tmp_max = (tmp_max >= checkTable[index][i])?tmp_max:checkTable[index][i];
????????}
}
??
int main(){
??
????????int q,left_length,right_length;
????????char left[1001],right[1001];
??
????????scanf("%d",&q);
??
????????for(int i=0;i<q;i++){
????????????????left_length=0;
????????????????right_length=0;
????????????????scanf("%s %s",left,right);
????????????????for(int k=0;left[k]!='\0';k++)left_length++;
????????????????for(int k=0;right[k]!='\0';k++)right_length++;
??
????????????????if(right_length>=left_length){
??
????????????????????????for(int k=left_length-1;k>=0;k--)calc(k,left,right,right_length);
????????????????}else{
??
????????????????????????for(int k=right_length-1;k>=0;k--)calc(k,right,left,left_length);
????????????????}
????????????????printf("%d\n",tmp_max);
????????????????tmp_max=0;
????????}
??
????????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 res = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for (int i = 0;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]);

			}
			res = max(res, c[i][j]);
		}
	}
	return res;
}

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 <vector>
#include <algorithm>
#include <numeric>
#define FOR(i,b,e) for(int i=b;i<e;i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;

string s1, s2;

int lcs(int n1, int n2) {
  if (n1 < 0 || n2 < 0) return 0;
  
  if (s1[n1] == s2[n2]) return 1 + lcs(n1 - 1, n2 - 1);
  else return max(lcs(n1, n2 - 1), lcs(n1 - 1, n2));
}

int main() {
	cin.tie(0);
 	ios::sync_with_stdio(false);

  int q; cin >> q;
  REP(i, q) {
    cin >> s1;
    cin >> s2;

    cout << lcs(s1.length() - 1, s2.length() - 1) << endl;
  }
}