Go: package main

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

func max(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s1 := scanner.Text()
		scanner.Scan()
		s2 := scanner.Text()
		s1, s2 = " " + s1 , " " + s2
		c := make([][]int, len(s1))
		for i := range c {
			c[i] = make([]int, len(s2))
		}

		LCS := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); 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])
				}
				LCS = max(LCS, c[i][j])
			}
		}
		fmt.Println(LCS)
	}
}

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;
	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]);
		}
		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 <string>
#include <iostream>
#include <algorithm>
using namespace std;
int q, n, m, dp[1007][1007]; string s, t;
int main() {
	cin >> q;
	while(q--) {
		cin >> s >> t;
		n = s.size(), m = t.size();
		for(int i = 0; i <= n; i++) dp[i][0] = 0;
		for(int j = 0; j <= n; j++) dp[0][j] = 0;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= n; j++) {
				dp[i][j] = (s[i - 1] == t[i - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]));
			}
		}
		cout << dp[n][m] << endl;
	}
}

C++: /*
 * Problem Description: Longest Common Subsequence
 * Category: Dynamic Programming
 * Author: Khan
 * Date: 18th October, 2017
 */

#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 maxLength = 0;
    x = ' ' + x;
    y = ' ' + y;
    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(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]);
            maxLength = max(maxLength, c[i][j]);
        }
    return maxLength;
}

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        string x, y;
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
    return 0;
}

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

using namespace std;

void lcs(string x,string y){
  int m=x.length();
  int n=y.length();
  int maxl=0;
  int c[m+1][n+1];
  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-1]==y[j-1])
        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]);
    }
  }
  cout << maxl << endl;
}

int main(){
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    string x,y;
    cin >> x >> y;
    lcs(x,y);
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;
int c[10000][10000]={};
int lcs(string s1,string s2){
  int m=s1.length(),n=s2.length(),maxl=0;
  s1=' '+s1;s2=' '+s2;
  rep(i,1000)rep(j,1000)c[i][j]=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]);
      maxl=max(maxl,c[i][j]);
    }
  }
  return maxl;
}
int main(){
  string str1,str2;
  int n;
  cin>>n;
  rep(i,n){
    cin>>str1>>str2;
    cout<<lcs(str1,str2)<<endl;
  }
  return 0;
}

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

const int MAX_N = 1000, MAX_M = 1000;
int dp[MAX_N + 1][MAX_M + 1];

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

	for (int i = 0;i < q;i++) {
		string x, y; cin >> x >> y;

		for (int i = 0;i <= x.size();i++)
			for (int j = 0;j <= y.size();j++) dp[i][j] = 0;

		for (int i = x.size() - 1;0 <= i;i--) {
			for (int j = y.size() - 1;0 <= j;j--) {
				if (x[i] == y[j]) dp[i][j] = dp[i + 1][j + 1] + 1;
				else dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
		cout << dp[0][0] << endl;
	}
    return 0;
}

C++: /*
 * ALDS1_10_C.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<cstring>
#include<algorithm>

int dp[1001][1001];

int lcm(char* X, char* Y, int nx, int ny) {
	dp[1][1] = (X[0] == Y[0]);
	for(int i=1; i<=nx; i++) {
		for(int j=1; j<=ny; j++) {
			dp[i][j] = (X[i-1]==Y[j-1]) + dp[i-1][j-1];
			dp[i][j] = std::max(dp[i-1][j], dp[i][j]);
			dp[i][j] = std::max(dp[i][j-1], dp[i][j]);
		}
	}
	return dp[nx][ny];
}

int main() {
	int q;
	scanf("%d", &q);
	char X[1001];
	char Y[1001];
	while(q--) {
		scanf("%s", X);
		scanf("%s", Y);
		int nx = (int)strlen(X);
		int ny = (int)strlen(Y);
		printf("%d\n", lcm(X, Y, nx, ny));
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) <= (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;


void solve(){
    string s, t;
    cin >> s >> t;
    vector<vector<int>> grid(s.size()+1, vector<int>(t.size()+1));

    grid[0][0] = 0;
    FOR(i,1,s.size()){
        grid[i][0] = 0;
    }
    FOR(i,1,t.size()){
        grid[0][i] = 0;
    }

    FOR(i,1,s.size()){
        FOR(j,1,t.size()){
            if(s[i-1]==t[j-1]){
                grid[i][j] = grid[i - 1][j - 1] + 1;
            }else{
                grid[i][j] = max(grid[i][j - 1], grid[i - 1][j]);
            }
        }

    }
    cout << grid[s.size()][t.size()] << endl;

}



int main(){

    int n;
    cin >> n;
    REP(i,n){
        solve();
    }

    return 0;
}