Go: package main

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

const max int = 1000 + 1
var A [][]int

func lcs(x, y string) int {
	x = " " + x
	y = " " + y
	for i:=0;i<len(x); i++ {
		for j:=0;j<len(y); j++ {
			A[i][j] = 0
		}
	}
	for i:=1; i<len(x); i++ {
		for j:=1; j<len(y); j++ {
			if x[i] == y[j] {
				A[i][j] = A[i-1][j-1] + 1
			} else if A[i-1][j] > A[i][j-1] {
				A[i][j] = A[i-1][j]
			} else {
				A[i][j] = A[i][j-1]
			}
		}
	}
	return A[len(x)-1][len(y)-1]
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num 
}

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


func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	A = make([][]int, max)
	for i := range A {
		A[i] = make([]int, max)
	}
	n := nextInt(scanner)
	for i:=0; i<n; i++ {
		x := nextStr(scanner)
		y := nextStr(scanner)
		fmt.Printf("%d\n", lcs(x, y))
	}
}

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

int main(int argc, char const *argv[]) {
  int q;
  std::cin >> q;
  for (size_t _ = 0; _ < q; _++) {
    std::string x, y;
    std::cin >> x;
    std::cin >> y;

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

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

int lcs(string str1, string str2)
{
	int len[1001][1001] = { 0 };

	int len1 = str1.size();
	int len2 = str2.size();
	str1 = ' ' + str1;
	str2 = ' ' + str2;

	for (int i = 0; i <= len1; i++)
		for (int j = 0; j <= len2; j++) len[i][j] = 0;

	for (int i = 1; i <= len1; i++)
	{
		for (int j = 1; j <= len2; j++)
		{
			if (str1[i] == str2[j]) len[i][j] = len[i - 1][j - 1] + 1;
			else len[i][j] = max(len[i - 1][j], len[i][j - 1]);
		}
	}
	return len[len1][len2];
}

int main()
{
	int n;
	string str1, str2;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> str1 >> str2;
		cout << lcs(str1, str2) << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int solve(string x, string y){
    int m = x.length();
    int n = y.length();
    int maxl = 0;
    int c[1001][1001];
    
    for(int i = 0; i < m; i++) c[i][0] = 0;
    for(int i = 0; i < n; i++) c[0][i] = 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][j-1], c[i-1][j]);
            }
            maxl = max(maxl,c[i][j]);
        }
    }
    return maxl;
}

int main(){
    int q, l = 0;
    string x,y;
    vector<int> a;

    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> x >> y;
        a.push_back(solve(x,y));
    }

    for(auto i: a){
        cout << i << endl;
    }

    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;
  Y=' '+Y;
  for(int i=0;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;
typedef long long ll;

int q;

int main(void){
    
    cin >> q;
    for(int i = 0; i < q; ++i){
        string a, b; cin >> a >> b;
        vector<vector<int>> dp(1001, vector<int>(1001, 0));
        
        for(int i = 1; i <= a.size(); ++i){
            for(int j = 1; j <= b.size(); ++j){
                dp[i][j] = max({dp[i - 1][j - 1] + (a[i - 1] == b[j - 1] ? 1 : 0), dp[i - 1][j], dp[i][j - 1]});
            }
        }
        
        cout << dp[a.size()][b.size()] << endl;
        
    }
    
    return 0;
}

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 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]);
            maxLength = max(maxLength, c[i][j]);
        }
    }
    return maxLength;
}

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    string x, y;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }
    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;
  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 <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

void slove(string X, string Y){
	int dp[1000][1000];//dp[X?????????][Y?????????] = LCS
	int sizex = X.size();
	int sizey = Y.size();

	//???????????????????????????????????????????????????0????????????????????\?????????
	X = ' ' + X;
	Y = ' ' + Y;

	reps(i, 1, sizex + 1) dp[i][0] = 0;//?????????????????????0??????dp???0
	reps(i, 1, sizey + 1) dp[0][i] = 0;//?????????????????????0??????dp???0

	int ans = 0;//????°??????????
	reps(i, 1, sizex + 1){
		reps(j, 1, sizey + 1){
			if(X[i] == Y[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
			else if(X[i] != Y[j]) dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);

			ans = max(ans, dp[i][j]);
		}
	}
	printf("%d\n", ans);
	return;
}

int main(void){
	int n; cin >> n;
	string s1, s2;
	rep(i, n){
		cin >> s1 >> s2;
		slove(s1, s2);
	}
	return 0;
}