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<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<array>
#include<cassert>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

const int MAX=1001;
const int INF=1<<29;

int dp[MAX][MAX];

int main(){

	int n;
	cin >> n;

	rep(i,n){
		string a,b;
		cin >> a >> b;
	
		fill_n((int *)dp,sizeof(dp)/sizeof(int),0);
		
		rep(i,a.size()+1){
			rep(j,b.size()+1){
				if(i==0||j==0) dp[i][j]=0;
				else if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
				else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
			}
		
		}

		cout << dp[a.size()][b.size()] << endl;
	
	}

}

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

int LCS(const char* s1, const char* s2){
	int i,j;
	int n1=strlen(s1);
	int n2=strlen(s2);
	int dp[n1+1][n2+1];
	for(i=0;i<=n1;i++)dp[i][0]=0;
	for(j=0;j<=n2;j++)dp[0][j]=0;
	for(i=1;i<=n1;i++){
		for(j=1;j<=n2;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]);
			}
		}
	}
	return dp[n1][n2];
}

int main(){
	int n;
	cin >> n;
	string s1;
	string s2;
	for (int i=0;i<n;i++){
		cin >> s1 >> s2;
		cout << LCS(s1.c_str(),s2.c_str());
		cout << endl;
	}
	return 0;
}

C++: def lcs(x, y)
  for i in range(1, len(x)):
    for j in range(1, lem(y)):
      if x[i] = y[j]:
        c[i][j] = c[i-1][j-1] + 1
      elif c[i-1][j]>c[i][j-1]:
        c[i][j] = c[i-1][j]
      else:
        c[i][j] = c[i][j-1]






q  = input()
x = [' ' for row in range(n+1)]
y = [' ' for row in range(n+1)]
c = [[' ' for col in range(1000)] for row in range(1000)]
for i in range(q):
  x = input()
  y = input()
  print lcs(x, y)

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int lcs(string X, string Y) {
  vector<vector<int>> c(2000, vector<int>(2000));
  int m = X.length();
  int n = Y.length();
  int maxl = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X.at(i - 1) == Y.at(j - 1)) {
        c.at(i).at(j) = c.at(i - 1).at(j - 1) + 1;
      } else {
        c.at(i).at(j) = max(c.at(i - 1).at(j), c.at(i).at(j - 1));
      }
      maxl = max(maxl, c.at(i).at(j));
    }
  }
  return maxl;
}

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

  vector<string> x(q);
  vector<string> y(q);
  rep(i, q) {
    cin >> x.at(i);
    cin >> y.at(i);
  }

  rep(i, q) { cout << lcs(x.at(i), y.at(i)) << endl; }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define P pair<int,int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'

int dp[1010][1010];

void solve(){
    string s,t;
    cin >> s >> t;

    int n = s.size();
    int m = t.size();
    memset(dp,0,sizeof(dp));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(s[i] == t[j]){
                dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + 1);
            }
            dp[i+1][j+1] = max(max(dp[i+1][j+1],dp[i+1][j]),dp[i][j+1]);
        }
    }
    cout << dp[n][m] << endl;
}

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

    while(q--){
        solve();
    }
}

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

// Longest Common Subsequence

class LCS {
    string S, T;
    vector <vector<int>> dp;

public:
    LCS(string &s, string &t) : S(s), T(t) {
        int sl = S.size(), tl = T.size();
        dp.assign(sl + 1, vector<int>(tl + 1, 0));

        for (int i = 0; i < sl; i++) {
            for (int j = 0; j < tl; j++) {
                if (S[i] == T[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]);
                }
            }
        }
    }

    int len() { return dp[S.size()][T.size()]; }

    string str() {
        string ret = "";
        int i = S.size(), j = T.size();
        while (dp[i][j]) {
            if (S[i - 1] == T[j - 1]) {
                i--, j--;
                ret = S[i] + ret;
            } else if (dp[i - 1][j] > dp[i][j - 1]) {
                i--;
            } else {
                j--;
            }
        }
        return ret;
    }
};


// verified
//   http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp
void AOJ_ALDS1_10_C() {
    int q;
    cin >> q;
    while (q--) {
        string x, y;
        cin >> x >> y;
        LCS lcs(x, y);
        cout << lcs.len() << "\n";
    }
}


// verified
//   https://atcoder.jp/contests/dp/tasks/dp_f
void AtCoder_2019_1_6_F() {
    string s, t;
    cin >> s >> t;
    LCS lcs(s, t);
    cout << lcs.str() << '\n';
}

int main() {
    AOJ_ALDS1_10_C();
    // AtCoder_2019_1_6_F();
    return 0;
}