Go: package main

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

const N = 1001

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

func lcs(x, y string) int {
	var c [N][N]int
	m := len(x)
	n := len(y)
	var maxl int

	x = " " + x
	y = " " + y

	for i := 1; i <= m; i++ {
		for 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
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	var out bytes.Buffer
	for i := 0; i < q; i++ {
		sc.Scan()
		s1 := sc.Text()
		sc.Scan()
		s2 := sc.Text()
		out.WriteString(fmt.Sprintf("%d\n", lcs(s1, s2)))
	}
	return strings.TrimRight(out.String(), "\n")
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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], i, j;
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for(i = 0; i <= m; i++) c[i][0] = 0;
  for(j = 1; j <= n; j++) c[0][j] = 0;

  for(i = 1; i <= m; i++) {
    for(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 c[m][n];
}

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;
#define rep(i,n) for(long long i=0;i<n;i++)
#define P pair<ll,ll>
#define F first
#define S second
#define all(a) (a.begin(),a.end())
long long INF=1000000000000000000;
long long mod=1000000007;
int dp[1010][1010];
int main(void){
    int q;cin>>q;string x,y;
    rep(k,q){
        cin>>x>>y;
        rep(i,1010)rep(j,1010)dp[i][j]=0;
        
        rep(i,x.size())rep(j,y.size()){
            if(x[i]==y[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[x.size()][y.size()]<<endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
int main(void){
    int cnt;
    int n;
    std::cin>>n;

    for(int k=0;k<n;k++){
        std::string str1;
        std::string str2;
        std::cin>>str1;
        std::cin>>str2;
        int l1=str1.size();
        int l2=str2.size();
        int A[l1][l2]={};

        for(int i=0;i<l1;i++){
            for(int j=0;j<l2;j++){
                if(i==0 or j==0){
                    if(str1[i]==str2[j]){
                        A[i][j]=1;
                    }else{
                        A[i][j]=0;
                    }
                }else if(str1[i]==str2[j]){
                    A[i][j]=A[i-1][j-1]+1;
                }else{
                    A[i][j]=std::max(A[i][j-1],A[i-1][j]);
                }
                //std::cout<<A[i][j]<<" ";
            }
            //std::cout<<"\n";
        }
        std::cout<<A[l1-1][l2-1]<<"\n";
    }
    return 0;
}

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

int main()
{
	int n;
	string b, c;
	cin >> n;
	for (int i = 0; i < n; i++){
		int a[1010][1010] = {};
		cin >> b >> c;
		for (int x = 1; x <= b.size(); x++){
			for (int y = 1; y <= c.size(); y++){
				if (b[x - 1] == c[y - 1]){
					a[x][y] = a[x - 1][y - 1] + 1;
				}
				else {
					a[x][y] = max(a[x][y - 1], a[x - 1][y]);
				}
			}
		}
		cout << a[b.size()][c.size()] << endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "DataStructure.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
typedef pair<int, int> p;
const int INF = 1000000000;
int main(){
	int n; cin >> n;
	for (int k = 0; k < n; k++) {
		char s[1000], t[1000];
		scanf("%s",&s); scanf("%s", &t);
		int i = 0, j = 0;
		int dp[1001][1001];
		fill(dp[0], dp[1001], 0);
		int res = 0;
		while (s[i] != '\0'){
			while (t[j] != '\0') 
			{
				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]);
				res = dp[i + 1][j + 1];
				//cout << "i " << i << "j " << j << endl;
				//cout << "dp" << dp[i + 1][j + 1] << endl;
				j++;
			}
			i++;
			j = 0;
		}

		cout << res << endl;
	}
	return 0;
}

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

int LCS(string p, string q) {
	vector<vector<int> > f(p.size()+1, vector<int>(q.size()+1,0));
	int t;
	for (int i = 1; i <= p.size(); i++) {
		for (int j = 1; j <= q.size(); j++) {
			if (p[i-1] == p[j-1])
				f[i][j] = f[i - 1][j - 1] + 1;
			else if (f[i][j - 1] > f[i - 1][j])
				f[i][j] = f[i][j - 1];
			else
				f[i][j] = f[i - 1][j];
		}
	}
	return f[p.size()][q.size()];
}

int main() {
	int n;
	string p[150];
	cin >> n;
	for (int i = 0; i < n; i ++) {
		cin >> p[2*i] >> p[2*i + 1];
	}
	for (int i = 0; i < n; i++) {
		cout << LCS(p[2*i], p[2 * i + 1])<<endl;
	}
	return 0;
}

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];    //c[i][k]???Xi??¨Yk???LCS??¨??????????????????
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X; // X[0]?????????????????\
    Y = ' ' + Y;
    for(int i=1;i<=m;i++) c[i][0] = 0;
    for(int k=1;k<=n;k++) c[0][k] = 0;

    for(int i=1;i<=m;i++){
        for(int k=1;k<=m;k++){
            if(X[i]==Y[k]){
                c[i][k] = c[i-1][k-1] + 1;
            } else {
                c[i][k] = max(c[i-1][k],c[i][k-1]);
            }
            maxl = max(maxl,c[i][k]);
        }
    }

    return maxl;
}

int main(){
    string s1,s2;
    int n; scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin >> s1 >> s2;
        printf("%d\n",lcs(s1,s2));
    }

    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
const int MAX = 2048;
inline int Max(int a, int b)
{
	return a > b ? a : b;
}
int dp[MAX][MAX];

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

	int t;
	std::string a, b;
	std::cin >> t;
	while (t--)
	{
		memset(dp, 0, sizeof(dp));
		std::cin >> a >> b;
		int len1 = a.size(), len2 = b.size();
		
		for (int i = 0; i < len1; ++i)
			for (int j = 0; j < len2; ++j)
			{
				if (a[i] == b[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]);
			}
		
		printf("%d\n", dp[len1][len2]);
	}
	
	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++){
    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;
}