Go: package main

import (
	"bufio"
	"os"
	"io"
	"strconv"
	"math"
	"fmt"
)

var (
	nstr   func() string
	stdout *bufio.Writer
)

func init() {
	nstr = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func main() {
	defer stdout.Flush()

	n := nint()
	xList := make([]string, n)
	yList := make([]string, n)

	for i:=0;i<n ;i++  {
		xList[i] = nstr()
		yList[i] = nstr()
	}

	for i := 0; i<n	; i++  {
		fmt.Println(lcs(xList[i], yList[i]))
	}

}

func lcs(x string, y string) int{
	var m = len(x)
	var n = len(y)

	c := make([][]int, m+1)
	for i:= range c{
		c[i] = make([]int, n+1)
	}
	for i:=	1;i<=m ;i++  {
		for j:=1;j<=n ;j++  {
			if x[i-1] == y[j-1]{
				c[i][j] = c[i-1][j-1] + 1
			}else{
				c[i][j] = int(math.Max(float64(c[i-1][j]), float64(c[i][j-1])))
			}


		}
	}
	return c[m][n]

}


func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func nint64() int64 {
	i, err := strconv.ParseInt(nstr(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func nint() int {
	return int(nint64())
}

func getIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nint()
	}
	return b
}

func getStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = nstr()
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2)
	} else {
		return strconv.FormatInt(i64, 2)
	}
}

func strReverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

C++: #include <iostream>
#include <algorithm>
#include<string.h>
using namespace std;
int LCS(char *x,char *y);
char x[1001], y[1001];
int lcs[1001][1001];
int main()
{
	int q,i,j;

	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> x;
		cin >> y;
		cout << LCS(x, y) << endl;
	}
}

int LCS(char *x, char *y)
{
	int i, j;
	int len_x, len_y;
	len_x = strlen(x);
	len_y = strlen(y);
	for (i = 0; i < len_x; i++) {
		for (j = 0; j < len_y; j++) {
			lcs[i][j] = '\0';
		}
		//cout << endl;
	}
	i = 0;
	while (x[i] != y[0]) {
		lcs[i][0] = 0;
		i++;
		if (i == len_x) break;

	}
	for (j = i; j < len_x; j++) {
		lcs[j][0] = 1;
	}
	while (y[i] != x[0]) {
		lcs[0][i] = 0;
		i++;
		if (i == len_y) break;
	}
	for (j = i; j < len_y; j++) {
		lcs[0][j] = 1;
	}

	for (i = 1; i <= len_x; i++) {
		for (j = 1; j <= len_y; j++) {
			if (x[i] == y[j]) {
				lcs[i][j] = lcs[i - 1][j - 1] + 1;
				//printf("lcs[%d][%d]=%d\n", i, j, lcs[i - 1][j - 1] + 1);
			}
			if (x[i] != y[j]) {
				lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
				//printf("lcs[%d][%d]=%d\n", i, j, max(lcs[i - 1][j], lcs[i][j - 1]));
			}
		}
	//cout << endl;

	}
	for (i = 0; i < len_x; i++) {
		for (j = 0; j < len_y; j++) {
			//printf("%d ", lcs[i][j]);
		}
		//cout << endl;
	}
	//cout << "len_x=" << len_x << endl << "len_y=" << len_y << endl;
			
	return lcs[i-1][j-1];
}

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

string x;
string y;

int lcs(string x, string y){

  int c[1024][1024] = {{}};

  for(int i = 1;i <= x.size();i++){
    for(int j = 1;j <= y.size();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]);

/*
      for(int k = 1;k <= x.size();k++){
        for(int l = 1;l <= y.size();l++){
          cout << c[i][j] << ' ';
        }
        cout << endl;
      }

      */
    }
  }

  return c[x.size()][y.size()];
}



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

  for(int i = 0;i < q;i++){
    cin >> x;
    cin >> y;
    cout << lcs(x,y) << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int dp[1010][1010];
int main(){
  int q;
  int ans[100]={};
  cin>>q;
  for(int cn=0;cn<q;cn++){
    string x,y;
    cin>>x>>y;
    for(int i=0;i<x.size();i++){
      for(int j=0;j<y.size();j++){
	if(x[i]==y[j])dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
	dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
	dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
      }
    }
    ans[cn]=dp[x.size()][y.size()];
    //cout<<dp[x.size()][y.size()]<<endl;
  }
  for(int i=0;i<q;i++)cout<<ans[i]<<endl;
  return 0;
}

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

using namespace std;

class Dataset{
private:
 string X;
 string Y;
public:
 Dataset(){
  string tmp = "";
  cin >> tmp; X = tmp; X = " " + X;
  cin >> tmp; Y = tmp; Y = " " + Y;
 };

 unsigned long getLongestCommonLength(){
  unsigned long Xsize = X.size();
  unsigned long Ysize = Y.size();
 
  vector< vector<unsigned long> > LC(Xsize, vector<unsigned long>(Ysize, 0));

  for(unsigned long X_i = 1; X_i < Xsize; ++X_i){
   for(unsigned long Y_i = 1; Y_i < Ysize; ++Y_i){
    unsigned long tmp = LC[X_i-1][Y_i-1];
    if(X[X_i] == Y[Y_i]) ++tmp;
    if(tmp < LC[X_i-1][Y_i]) tmp = LC[X_i-1][Y_i];
    if(tmp < LC[X_i][Y_i-1]) tmp = LC[X_i][Y_i-1];
    LC[X_i][Y_i] = tmp;
//cout << LC[X_i][Y_i] << " ";
   }
//cout << endl;
  }

  return LC[Xsize-1][Ysize-1];
 };


protected:
};

int main(){
 long datasetNum = 0; cin >> datasetNum;
 for(unsigned long dataset_i = 0; dataset_i < datasetNum; ++dataset_i){
  Dataset data;
  cout << data.getLongestCommonLength() << 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 <string>
#include <algorithm>

using namespace std;

int main() {
  int T;
  cin >> T;
  for (int t=0; t<T; t++) {
    string word1, word2;
    cin >> word1 >> word2;
    int m = word1.size();
    int n = word2.size();
    int c[m+1][n+1]={};
    int max_len = 0;
    word1 = ' ' + word1;
    word2 = ' ' + word2;

    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        if (word1[i] == word2[j]) {
          c[i][j] = c[i-1][j-1] + 1;
        }
        else {
          c[i][j] = max(c[i-1][j], c[i][j-1]);
        }
        max_len = max(max_len, c[i][j]);
      }
    }
    cout << max_len << endl;
  }
  return 0;
}

#if 0
???????????????30????????????
?????????0??????????????????????????????????¬?????????????0??§??????????????????????????????1???????§????????????¨??§
????????????????????????????????????????????????????????????
#endif

C++: #include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int q;

  	cin >> q;
	for(int i=0;i<q;i++){
		string x, y;
		cin >> x >> y;
        int n, m;
        n = x.size();
        m = y.size();
		int dp[n+1][m+1];
		for(int j=0;j<=n;j++){
          for(int k=0;k<=m;k++){
			dp[j][k] = 0;
			}
		}
		
		for(int j=0;j<n;j++){
			for(int k=0;k<m;k++){
				if(x[j]==y[k]){
					dp[j+1][k+1] = max(dp[j][k+1], max(dp[j+1][k], dp[j][k]+1));
				}else{
					dp[j+1][k+1] = max(dp[j][k+1], max(dp[j+1][k], dp[j][k]));
				}
			}
		}
		
		
		
		cout << dp[n][m] <<endl;
  
	}
}