Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func f() {
	var S, T string
	fmt.Scan(&S)
	fmt.Scan(&T)
	lenS, lenT := len(S), len(T)
	dp := make([][]int, lenS+1)
	for i:=0; i<lenS+1; i++ {
		dp[i] = make([]int, lenT+1)
	}
	for i:=1; i<lenS+1; i++ {
		for j:=1; j<lenT+1; j++ {
			if S[i-1] == T[j-1] {
				dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
		}
	}
	fmt.Println(dp[lenS][lenT])
}

func main(){
	var n int 
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		f()
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxx = 1010;
int c[maxx][maxx];

int lcs(char s1[],char s2[]) {
	int m = strlen(s1), n = strlen(s2);
	for (int i = 1; i <= m; i++)
		c[i][0] = 0;
	for (int i = 1; i <= n; i++)
		c[0][i] = 0;

	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (s1[i] == s2[j])
				c[i][j] = c[i - 1][j - 1] + 1;
			else
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
		}
	}
	return c[m][n];
}
int main()
{
	char s1[maxx], s2[maxx];
	int t;
	scanf("%d", &t);
	getchar();
	for (int i = 0; i < t; i++) {
		scanf("%s %s", s1, s2);
		printf("%d\n", lcs(s1,s2));
	}

	return 0;
}

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

int main(){
    int q;
    cin >> q;
    int dp[1001][1001] = {0};
    for(int i = 0; i < q; i++){
        string S1, S2;
        cin >> S1 >> S2;
        const int m = S1.size();
        const int n = S2.size();
        for(int j = 0; j < m; j++){
            bool flag = 1;
            for(int k = 0; k < n; k++){
                if(j == 0 && k == 0) dp[j][k] = 0;
                else if(j == 0) dp[j][k] = dp[j][k-1];
                else if(k == 0) dp[j][k] = dp[j-1][k];
                else{
                    dp[j][k] = max(dp[j-1][k],dp[j][k-1]);
                }
                if(S1[j] == S2[k] && flag) {
                    //cout << j << " " << k << " " << dp[j][k]++ <<endl;
                    dp[j][k]++;
                    flag = 0;
                }
            }
        }
        cout << dp[m-1][n-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 <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

int dp[1005][1005];

signed main(){
  int n;
  cin>>n;
  for(int i=0; i<n; i++){
    string s1,s2;
    cin>>s1>>s2;
    s1=" "+s1;
    s2=" "+s2;
    for(int i=0; i<=s1.size(); i++) for(int j=0; j<=s2.size(); j++) dp[i][j]=0;
    for(int i=1; i<s1.size(); i++){
      for(int j=1; j<s2.size(); j++){
        if(s1[i]==s2[j]) dp[i][j]=dp[i-1][j-1]+1;
        else dp[i][j]=max(dp[i-1][j],dp[j-1][i]);
      }
    }
    cout<<dp[s1.size()-1][s2.size()-1]<<en;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int dp(int i, int j) {

}

int solve(string X, string Y) {
    vector<vector<int > > dp ;
    dp.resize(X.length() + 1);
    for (int i = 0; i <= X.length(); ++i) {
        dp[i].resize(Y.length() + 1);
    }

    for (int k = 0; k <= Y.length(); ++k) {
        dp[0][k] = 0;
    }
    for (int k = 0; k <= X.length(); ++k) {
        dp[k][0] = 0;
    }

    for (int i = 1; i <= X.length(); ++i) {
        for (int j = 1; j <= Y.length(); ++j) {
            if (X[i] == Y[j]) {
                dp[i][j] = 1 + dp[i-1][j-1];
            } else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    return dp[X.length()][Y.length()];
}
int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        string X, Y;
        cin >> X >> Y;
        cout << solve(X, Y) << endl;
    }

    return 0;
}