Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	results := []int{}
	for i := 0; i < n; i++ {
		results = append(results, resolveInstance())
	}
	for _, v := range results {
		fmt.Println(v)
	}
	return
}

func resolveInstance() int {
	x, y := scanString(sc), scanString(sc)
	lx, ly := len(x), len(y)
	dp := make([][]int, lx+1)
	dp[0] = make([]int, ly+1)
	for i := 1; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
		dp[i][0] = dp[i-1][0]
		for j := 1; j <= ly; j++ {
			dp[i][j] = dp[i-1][j]
			if dp[i][j] < dp[i][j-1] {
				dp[i][j] = dp[i][j-1]
			}
			if x[i-1] == y[j-1] {
				cL := dp[i-1][j-1] + 1
				if dp[i][j] < cL {
					dp[i][j] = cL
				}
			}
		}
	}
	return dp[lx][ly]
}

const (
	remove = 0 + iota
	match
)

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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

int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++){
        string X,Y;cin>>X>>Y;
        int M[X.size()][Y.size()]={};
        //まずは端を埋める
        int flg=0;
        for(int i=0;i<Y.size();i++){//Xの一文字目を固定
            if(X[0]==Y[i])flg=1;
            if(flg)M[0][i]=1;
        }
        flg=0;
        for(int i=0;i<X.size();i++){//Yの一文字目を固定
            if(Y[0]==X[i])flg=1;
            if(flg)M[i][0]=1;
        }
        for(int i=1;i<X.size();i++){
            for(int j=1;j<Y.size();j++){
                if(X[i]==Y[j]){
                    M[i][j]=M[i-1][j-1]+1;
                }else{
                    M[i][j]=max(M[i-1][j],M[i][j-1]);
                }
            }
        }

        cout<<M[X.size()-1][Y.size()-1]<<endl;
    }
    return 0;
}

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

static const int N = 1000;

int longestCommonSubsequence(string X, string Y)  {
  int c[N + 1][N + 1];
  int m = X.size();
  int n = Y.size();
  int max1 = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 0; i <= m; i++) 
    c[i][0] = 0;
  for (int j = 1; j <= n; j++)
    s[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]);
      }
      max1 = max(max1, c[i][j]);
    }
  }
  return max1;
}
 
int main()  {
  string s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)  {
    cin >> s1 >> s2;
  cout << longestCommonSubsequence(s1, s2) << endl;
  }
  return ;
}

C++: #include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
  int n;
  cin>>n;
  rep(i,n){
      string s,t;
      cin>>s>>t;
      
      vvll dp(s.size()+1,vll(t.size()+1));
      rep(j,s.size()+1)dp.at(j).at(0)=0;
      rep(j,t.size()+1)dp.at(0).at(j)=0;
      
      rep(j,s.size()){
          rep(k,t.size()){
              if(s.at(j)==t.at(k))dp.at(j+1).at(k+1)=dp.at(j).at(k)+1;
              else dp.at(j+1).at(k+1)=max(dp.at(j+1).at(k),dp.at(j).at(k+1));
          }
      }
      cout<<dp.at(s.size()).at(t.size())<<endl;
  }
}

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 <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int n, dp[1024][1024];
	string a, b;
	cin >> n;
	
	while(n)
	{
		n--;
		memset(dp, 0, sizeof(dp));

		cin >> a;
		cin >> b;

		for(int i = 1; i <= a.size(); i++)
		{
			for(int j = 1; j <= b.size(); j++)
			{
				if(a[i+1] == b[j+1])
				{
					dp[i+1][j+1] = max(dp[i][j] + 1, max(dp[i + 1][j], dp[i][j + 1]));
				}
				else
				{
					dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
				}
			}
		}

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

C++: #include<iostream>
#include<string>
int main()
{
  int n;
  int an[1000];
  int l=0;
  std::cin>>n;
  std::string x;
  std::string y;
  int ans[1001][1001];
  int j,k;
  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<=1000;j++){
      for(int k=0;k<=1000;k++){
	ans[j][k]=0;
      }
    }
    for(int j=0;j<x.size();j++){
      for(int k=0;k<y.size();k++){
	if(x[j]==y[k]){
	  ans[j][k]=ans[j-1][k-1]+1;
	}else{
	  if(ans[j][k-1]>ans[j-1][k]){
	    ans[j][k]=ans[j][k-1];
	  }else{
	    ans[j][k]=ans[j-1][k];
	  }
	}
      }
    }
    std::cout<<ans[x.size()-1][y.size()-1]<<'\n';  
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 1000;
const int N = 150;

int dp[MAX+1][MAX+1];

int lcs(string X, string Y) {
	rep(i, X.size()+1) { rep(j, Y.size()+1) {
		if (i == 0 || j == 0)
			dp[i][j] = 0;
		else if (X[i-1] == Y[j-1])
			dp[i][j] = dp[i-1][j-1] + 1;
		else
			dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
	} }
	return dp[X.size()][Y.size()];
}

int main() {
	int q; cin >> q;
	string X, Y;
	rep(i, q) {
		cin >> X >> Y;
		cout << lcs(X, Y) << endl;
	}
}