Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <random>
#include <map>

using namespace std;

int LCS[1010][1010] = {};

int LCSLength(string strX,string strY) {

    int strXSize = strX.length();
    int strYSize = strY.length();
    for (int i = 0; i < strXSize + 1; i++) {
	for (int j = 0; j < strYSize + 1; j++) {
	    if (i == 0 || j == 0) {
		LCS[i][j] = 0;
	    }
	}
    }

    for (int i = 1; i < strXSize + 1; i++) {
	for (int j = 1; j < strYSize + 1; j++) {

	    //LCS[i]==LCS[j]
	    if (strX[i - 1] == strY[j - 1]) {
		LCS[i][j] = LCS[i - 1][j - 1] + 1;
	    }
	    else {
		LCS[i][j] = max(LCS[i][j - 1], LCS[i - 1][j]);
	    }
	}
    }

    return LCS[strXSize][strYSize];
}

int main() {

    //cin.tie(0);
    //ios::sync_with_stdio(false);

    int q; scanf("%d", &q);

    string strX;
    string strY;
    while (q-- > 0) {
	cin >> strX;
	cin >> strY;
	printf("%d\n", LCSLength(strX, strY));
    }



    return 0;

}

C++: // ALDS1_10_C
#include <bits/stdc++.h>
#define endl "\n"
#define _GLIBCXX_DEBUG //配列外参照エラー表示,gcc依存
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ipair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int q;
    cin>>q;
    rep(i,q){
        string a,b;
        cin>>a>>b;
        int la=a.size(),lb=b.size();
        vector<vector<int>> dp(la+10,vector<int>(lb+10,0));
        for(int i=1;i<=la;i++){
            for(int j=1;j<=lb;j++){
                if(a[i-1]==b[j-1]) dp[i][j]=max({dp[i-1][j-1]+1,dp[i-1][j],dp[i][j-1]});
                else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        cout<<dp[la][lb]<<endl;
    } 
    return 0;
}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

int q;
string s1,s2;
int ans;
int dp[150][150];
int main()
{
	cin>>q;
	rep(i,q){
		cin>>s1>>s2;
		rep(i,s1.size()){
			rep(j,s2.size()){
				dp[i][j]=0;
			}
		}
		if(s1[0]==s2[0]) dp[0][0]=1;
		rep1(i,s1.size()-1){
			if(s1[i]==s2[0]) dp[i][0]=1;
			dp[i][0]=max(dp[i][0],dp[i-1][0]);
		}
		rep1(i,s2.size()-1){
			if(s1[0]==s2[i]) dp[0][i]=1;
			dp[0][i]=max(dp[0][i],dp[0][i-1]);
		}
		rep1(i,s1.size()-1){
			rep1(j,s2.size()-1){
				dp[i][j]=max( dp[i-1][j], dp[i][j-1] );
				if(s1[i]==s2[j]) dp[i][j]= max(dp[i][j],dp[i-1][j-1]+1);
			}
		}
		cout<<dp[s1.size()-1][s2.size()-1]<<endl;
	}
}

C++: //
//  main.cpp
//  longest_common_subsequence
//
//  Created by ???????????? on 2017/10/17.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

char X[1005];
char Y[1005];

void lcs(){
    size_t m = strlen(X);
    size_t n = strlen(Y);
    int c[m+1][n+1];
    c[0][0] = 0;
    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 if(c[i-1][j] >= c[i][j-1]){
                c[i][j] = c[i-1][j];
            }
            else{
                c[i][j] = c[i][j-1];
            }
        }
    }
    cout << c[m][n] << endl;
//    cout << c[m+1][n+1] << endl;
}

int main(int argc, const char * argv[]) {
    int n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%s", X);
        scanf("%s", Y);
        lcs();
    }
//    std::cout << "Hello, World!\n";
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
//BEGIN CUT HERE
int lcs(string X,string Y){
  const int N=max(X.size(),Y.size())+1;
  vector<vector<int> > c(N,vector<int>(N,0));
  int m = X.size();
  int n = Y.size();
  int 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;
}
//END CUT HERE
int main(){
  int q;
  cin>>q;
  while(q--){
    string s,t;
    cin>>s>>t;
    cout<<lcs(s,t)<<endl;
  }
  return 0;
}
/*
verified on 2017/06/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C
*/