Go: package main

/*
最長共通部分列
*/

import (
	"bufio"
	"bytes"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func larger(l, r int) int {
	if l > r {
		return l
	}
	return r
}

var memo [1001][1001]int

func countLCS(x, y string) int {
	x = " " + x
	y = " " + y
	max := 0
	for xi := 1; xi < len(x); xi++ {
		for yi := 1; yi < len(y); yi++ {
			if x[xi] == y[yi] {
				memo[xi][yi] = memo[xi-1][yi-1] + 1
			} else {
				memo[xi][yi] = larger(memo[xi-1][yi], memo[xi][yi-1])
			}
			max = larger(max, memo[xi][yi])
		}
	}
	return max
}

func main() {
	scanner := makeScanner(1024)
	q := eGetInt(scanner)
	for i := 0; i < q; i++ {
		x := eGetLine(scanner)
		y := eGetLine(scanner)
		fmt.Println(countLCS(x, y))
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	buf.WriteString("[")
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = ", "
	}
	buf.WriteString("]")
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func max(a ints) (int, bool) {
	if len(a) == 0 {
		return 0, false
	}
	m := a[0]
	for _, e := range a {
		if e > m {
			m = e
		}
	}
	return m, true
}
func min(a []int) int {
	m := a[0]
	for _, v := range a {
		if v < m {
			m = v
		}
	}
	return m
}

func sum(a ints) int {
	if len(a) == 0 {
		return 0
	}
	sum := 0
	for _, e := range a {
		sum += e
	}
	return sum
}
func find(n int, a ints) int {
	for i, v := range a {
		if n == v {
			return i
		}
	}
	return -1
}

C++: #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define MAX 150
void solve(void);
int q,count[MAX][MAX]={},xlength,ylength;
char X[MAX],Y[MAX];

void solve(void){
  int i,j;

  for(i=1;i<=strlen(X);i++){
    for(j=1;j<=strlen(Y);j++){
      if(X[i-1]==Y[j-1]) count[i][j]=count[i-1][j-1]+1;
      else if(count[i-1][j]>=count[i][j-1]) count[i][j]=count[i-1][j];
      else count[i][j]=count[i][j-1];
    }
  }

  xlength=strlen(X);
  ylength=strlen(Y);
}
    

int main()
{
  int i;
  
  scanf("%d",&q);

  for(i=1;i<=q;i++){
    scanf("%s",X);
    scanf("%s",Y);
    solve();
    printf("%d\n",count[xlength][ylength]);
  }

  /*for(i=0;i<q;i++){
    printf("%d\n",count[][]);
    }*/

  return 0;
}

C++: #include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950

void C (string x, string y){
    int p = x.size() ;
    int q = y.size() ;
    vector<vector<int>> dp (p + 1 , vector<int> (q + 1)) ;
    rep(i, p){
        rep(j, q){
            if(x.at(i) == y.at(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[p][q] << endl;
}

int main() {
    int n ; 
    cin >> n ;
    vector<string> s (n) ;
    vector<string> t (n);
    rep(i, n){
        cin >> s[i] ;
        cin >> t[i] ;
    }
    rep(k, n){
        C(s[k], t[k])  ;
    }
}

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;
  }
}