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

int main()
{
  std::vector<std::string> x;
  std::vector<std::string> y;
  std::vector<std::string> z;

  int n;
  std::string str1;
  std::string str2;
  std::string str_z;
  std::cin>>n;
  if(n>150){
   std::cout<<"EEROR\n";
   }
  for(int k=0;k<n;k++){
    std::cin>>str1;
    x.push_back(str1);
    std::cin>>str2;
    y.push_back(str2);
  }
  /*for(int i=0;i<n;i++){
    for(int j=0;j<x[i].size();j++){
      std::cout<<x[i][j]<<":";
      if(j==x[i].size()-1){
	std::cout<<"\n";
      }
    }   
  } 
  for(int i=0;i<n;i++){
    for(int j=0;j<y[i].size();j++){
      std::cout<<y[i][j]<<":";
      if(j==y[i].size()-1){
	std::cout<<"\n";
      }
    }
  }
  std::cout<<x[0].size()<<" "<<y[0].size()<<"\n";
  std::cout<<x[0][2]<<"\n";
  */
  int count[n]={0};
  for(int i=0;i<n;i++){
    int xl=0,yl=0,tmp=0,judege=0;
    if(x[i].size()<=y[i].size()){
      while(judege==0){
	//std::cout<<i<<" xl:"<<xl<<" yl:"<<yl<<"\n";
	if(xl==x[i].size()&&yl==y[i].size()){
	  judege=-1;
	}else if(yl==y[i].size()){
	  yl=tmp;
	  xl++;
	}else if(x[i][xl]==y[i][yl]){
	  count[i]++;
	  str_z=x[i][xl];
	  z.push_back(str_z);
	  xl++;
	  yl++;
	  tmp=yl;
	}else{
	  yl++;
	}
      }
    }else{
     while(judege==0){
	//std::cout<<i<<" xl:"<<xl<<" yl:"<<yl<<"\n";
	if(xl==x[i].size()&&yl==y[i].size()){
	  judege=-1;
	}else if(xl==x[i].size()){
	  xl=tmp;
	  yl++;
	}else if(x[i][xl]==y[i][yl]){
	  count[i]++;
	  str_z=x[i][xl];
	  z.push_back(str_z);
	  xl++;
	  yl++;
	  tmp=xl;
	}else{
	  xl++;
	}
      } 

    }
  }
  for(int i=0;i<n;i++){
    std::cout<<count[i]<<"\n";
    /*for(int j=0;j<z.size();j++){
      std::cout<<z[j];
    } 
    std::cout<<"\n";
    */
  }


  return 0;
}

C++: // Last Change: 12/29/2018 23:21:03.
//
// XとYの先頭に空白を入れることで、探索するべき要素のindexを0~m-1ではなく
// 1~mにしている。これにより、一番最初のcの更新において、i=j=0におけるc[i-1][j-1]
//すなわちc[-1][-1]にアクセスしてしまうことを防いでいる。
//
//***********************************************************************
//下から順番に計算していく方法
//
//***********************************************************************

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define MAXLENGTH 1001

int LCS(string, string);

int LCS(string X, string Y) {
  static int c[MAXLENGTH][MAXLENGTH];
  for (int i = 0; i < MAXLENGTH; i++) {
    c[i][0] = c[0][i] = 0;
  }
  int m, n, maxL;
  m = X.size();
  n = Y.size();
  maxL = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  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 X, Y;
  for (int i = 0; i < q; i++) {
    cin >> X >> Y;
    cout << LCS(X, Y) << endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
const int MAX_S = 1005;
using namespace std;

int main(void) {
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        string x, y;
        cin >> x >> y;
        x = ' ' + x;
        y = ' ' + y;

        int dp[MAX_S][MAX_S];
        for (auto j = 1; j < x.size(); j++) {
            dp[j][0] = 0;
        }
        for (auto k = 1; k < y.size(); k++) {
            dp[0][k] = 0;
        }

        int maxlength = 0;
        for (auto j = 1; j < x.size(); j++) {
            for (auto k = 1; k < y.size(); k++) {
                if (x[j] == y[k]) {
                    dp[j][k] = dp[j-1][k-1] + 1;
                } else {
                    dp[j][k] = max(dp[j-1][k], dp[j][k-1]);
                }
                maxlength = max(maxlength, dp[j][k]);
            }
        }

        cout << maxlength << endl;
    }

    return 0;
}

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

using namespace std;

static const int N = 100;

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; // X[0]?????????????????\
  Y = ' ' + Y; // Y[0]?????????????????\
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[i]) {
        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 <vector>

int main(int argc, char const *argv[]) {
  int q;
  std::cin >> q;
  for (size_t _ = 0; _ < q; _++) {
    std::string x, y;
    std::cin >> x;
    std::cin >> y;

    std::vector<std::vector<int> > dp(x.size()+1, std::vector<int>(y.size()+1));
    for (size_t ii=0; ii<x.size(); ++ii){
      for(size_t jj=0; jj<y.size(); ++jj){
        size_t i = ii + 1;
        size_t j = jj + 1;
        if (x[ii]==y[jj]){
          dp[i][j] = dp[i-1][j-1] + 1;
        }
        else{
          dp[i][j] = std::max(dp[i-1][j], dp[i][j-1]);
        }
      }
    }
    std::cout << dp[x.size()][y.size()] << std::endl;
  }
  return 0;
}