Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
int main(){
  int q;
  std::cin>>q;
  std::vector<std::string> str1,str2;
  std::string str;
  for(int i=0;i<q;i++){
    std::cin>>str;
    str1.push_back(str);
    std::cin>>str;
    str2.push_back(str);
    //std::cout<<str1[i][0]<<"\n";
    //std::cout<<str2[i][0]<<"\n";
  }
  
 
  for (int i = 0; i < q; i++) {
	  int ans[str1[i].length()+1][str2[i].length()+1];
	  for (int j = 0; j < str1[i].length() + 1; j++) {
		  for (int k = 0; k < str2[i].length() + 1; k++) {
			  
			  if (j == 0 || k == 0) {
				  ans[j][k] = 0;
			  }else {
				  //std::cout << " str1= " << str1[i][j-1] << " str2= " << str2[i][k-1] << " \n ";
				  if (str1[i][j-1] == str2[i][k-1]){
					  //std::cout << "ppp";
					  ans[j][k] = std::max({ ans[j - 1][k - 1] + 1,ans[j - 1][k],ans[j][k - 1] });
					  //ans[j][k] = std::max({ 1,2,3 });
				  }else {
					  ans[j][k] = std::max(ans[j - 1][k], ans[j][k - 1]);
				  }
			  }
			  //std::cout << ans[j][k] << " ";
			  
		  }
		  //std::cout << "\n";
	  }
	  std::cout << ans[str1[i].length()][str2[i].length()] << "\n";
  }
  

  return 0;
}

C++: /*
* @Author: Samson
* @Date:   2018-06-11 11:31:19
* @Last Modified by:   Samson
* @Last Modified time: 2018-06-11 11:46:49
*/
//   @URL : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C
#include<bits/stdc++.h>
#include<algorithm>
#include <cstdlib>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e3+10;

string a,b;
int f[MAXN][MAXN];

int solve()
{
	memset(f,0,sizeof f);
	int lena = a.size(),lenb = b.size();
	int maxv = 0;
	a = ' '+a,	b = ' '+b;
	for(int i = 1; i <= lena; ++i)
	{
		for(int j = 1; j <= lenb; ++j)
		{
			if(a[i] == b[j])
				f[i][j] = f[i-1][j-1]+1;
			else
				f[i][j] = max(f[i-1][j],f[i][j-1]);
			if(f[i][j] > maxv)	maxv = f[i][j];
		}
	}
	return maxv;
}
int main(void)
{
	ios::sync_with_stdio(false); 
	//cin.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		cin>>a>>b;
		cout<<solve()<<'\n';
	}
	return 0;
}

C++: #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    rep(i, N) {
        string s, t;
        cin >> s >> t;
        int N = s.size(), M = t.size();
        vector<vector<int>> dp(N + 1, vector<int>(M + 1));

        rep(i, N) {
            rep(j, M) {
                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(dp[i + 1][j + 1], dp[i][j + 1]);
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
            }
        }

        cout << dp[N][M] << endl;
    }
}

C++: #include "bits/stdc++.h"
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 <bits/stdc++.h>
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

vector<vector<int>> dp(2000, vector<int>(2000));

void solve(string s, string t){
  int n = int(s.size());
  int m = int(t.size());

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; 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]);
      }
    }
  }

  cout << dp[n][m] << endl;
}

int main(){
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    string s, t;
    cin >> s >> t;
    solve(s, t);
  }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
static const int N = 1000;
void lcs(string x, string y)
{
    int m = x.length(), n = y.length();
    int c[1001][1001]; //c[0][0] = 0;
    int maxv = 0;
    x = ' ' + x;
    y = ' ' + y;
    for(int i=0; i<=m; i++) c[i][0] = 0;
    for(int j=0; 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]);
            maxv = max(maxv, c[i][j]);
        }
    }
    printf("%d\n", maxv);
}
int main()
{
    int q; string x, y;
    cin >> q;
    for(int i=0; i<q; i++)
    {
        cin >> x >> y;
        lcs(x, y);
    }
    //system("pause");
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>

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;    // X[0] に空白を挿入
    Y = ' ' + Y;    // Y[0] に空白を挿入
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 0; 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<stdio.h>
#include<string.h>
#define max(a,b) ((a)>(b) ? (a):(b))
int dp[1001][1001];
int lcs(char *s,char *t){
    int i,j,ls,lt;

    ls=strlen(s);
    lt=strlen(t);
    for(i=0;i<ls;i++){
	for(j=0;j<lt;j++){
	    if(s[i]==t[j]) dp[i+1][j+1]=dp[i][j]+1;
	    else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
	}
    }
    return dp[ls][lt];
}
int main(){
    char s[1001],t[1001];
    int k;

    scanf("%d", &k);
    while(k--){
	scanf("%s%s", s, t);
	printf("%d\n",lcs(s,t));
    }

    return 0;
}