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 <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<iostream>
using namespace std;
int lcs(string a,string b)
{
    if(a.length()<=0||b.length()<=0)
    {
        return 0;
    }
    else if(a[a.length()-1]==b[b.length()-1])
    {
        return 1+lcs(a.substr(0,a.length()-1),b.substr(0,b.length()-1));
    }
    else
    {
        return max(lcs(a.substr(0,a.length()),b.substr(0,b.length()-1)),lcs(a.substr(0,a.length()-1),b.substr(0,b.length())));
    }
};
int main()
{
    int num;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        string a,b;
        cin>>a>>b;
        cout<<lcs(a,b)<<endl;
    }
}

C++: #include <stdio.h>

int judge(char A[], char B[]){
  int a=0, b=0, sw=0, ans=0;
  int i, j;
  int C[1001][1001];
  
  while(sw == 0){
    if(A[a] != '\0')
      a++;
    else
      sw = 1;
  }
  
  sw = 0;
  
  while(sw = 0){
    if(B[b] != '\0')
      b++;
    else
      sw = 1;
  }
  
  for(i=1; i<a+1; i++)
    C[i][0] = 0;
  for(i=1; i<b+1; i++)
    C[0][i] = 0;
  
  for(i=1; i<a+1; i++){
    for(j=1; j<b+1; j++){
      if(A[i-1] == B[j-1])
        C[i][j] = C[i-1][j-1] + 1;
      else if(C[i-1][j] >= C[i][j-1])
        C[i][j] = C[i-1][j];
      else
        C[i][j] = C[i][j-1];
      if(ans < C[i][j])
        ans = C[i][j];
    }
  }
  
  return ans;
}

int main(){
  char A[1000], B[1000];
  int n, i;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%s", A);
    scanf("%s", B);
    printf("%d\n", judge(A, B));
  }
  
  return 0;
}

C++: #if 0

#endif

#include <iostream>
#include <string>
using namespace std;

int main(){
	int q;
	string X,Y;
	string x,y;
	int L[1000][1000];
	
	for(int i=0;i<1000;++i) //???????????\????????????L????????????
		for(int j=0;j<1000;++j)
			L[i][j]=0;
	
	cin >> q;
	for(int i=0;i<q;++i){
		cin >> X >> Y;
		for(int j=0;j<X.length();++j)
			for(int k=0;k<Y.length();++k){
				x+=X[j];
				y+=Y[k];
				if(j==0||k==0)
					L[j][k]=0;
				else if(x[j]==y[k])
					L[j][k]=1+L[j-1][k-1];
				else
					max(L[j-1][k],L[j][k-1]);
			}
			
	}
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
  char str1[100],str2[100];
  int LCS[100][100]={0};
  int length1,length2;
  int n;
  scanf("%d",&n);
  for(int s=1;s<=n;s++){
   while(cin>>str1>>str2){
     length1=strlen(str1);
     length2=strlen(str2);
     for(int i=0;i<=length1-1;i++){
       LCS[i][0]=0;
     }
     for(int j=0;j<=length2-1;j++){
       LCS[0][j]=0;
     }
     for(int i=1;i<=length1;i++){
       for(int j=1;j<=length2;j++){
         if(str1[i-1]==str2[j-1]) {
           LCS[i][j]=LCS[i-1][j-1]+1;
         }
         else LCS[i][j]=max(LCS[i-1][j],LCS[i][j-1]);
       }
     }
     printf("%d\n",LCS[length1][length2]);
   }
 }
   return 0;
}

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

int main(){
  int q, cnt, max;
  string str1, str2;
  char ch1, ch2;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> str1 >> str2;
    max = 0;
    //cout << "cin >> str1 >> str2" << endl;
    for(int j=0;j<(int)str1.size();j++){
      for(int k=0;k<(int)str2.size();k++){
	//cout << "j = " << j << ", k = " << k << endl;
        cnt = 0;
	int l = 0;
	while(1){
	      //str1[j+l] || str2[k+l] || str1[j+l] == str2[k+l]){
	  ch1 = str1[j+l];
	  //  cout << ch1 << " ";
	  ch2 = str2[k+l];
	  //  cout << ch2 <<endl;
	  if(ch1 == ch2 && ch1 != '\0'){
     	    cnt++;
	    l++;
	    //	    cout << "一致" << endl;
	  }else break;
	}
	if(cnt > max) max = cnt;
      }
    }
    cout << max << endl;
  }
}

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

	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; 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(){
	string s1, s2;
	int q;
	cin >> q;
	for (int i=0; i<q;i++){
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << 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<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	
	vector<int> v;
	int n=0;
	scanf("%d", &n);
	string a;
	string b;
	for (int i = 0; i < n; ++i)
	{
		char a1[1000],b1[1000];
		string a(a1);
		string b(b1);
		vector<vector<int> > dp(int(a.size()), vector<int>(int(b.size())));
		
		if(a[0]==b[0]) dp[0][0]=1;
		for (int i = 0; i < a.size(); ++i)
		{
			if(a[i]==b[0]){
				dp[i][0]=1;
			} else {
				dp[i][0]=dp[i-1][0];
			}
		}
		for (int i = 0; i < b.size(); ++i)
		{
			if(a[0]==b[i]){
				dp[0][i]=1;
			} else {
				dp[0][i]=dp[0][i-1];
			}
		}
		for (int i = 1; i < a.size(); ++i)
		{
			for (int j = 1; j < b.size(); ++j)
			{
				if(a[i]==b[j]){
					dp[i][j]=dp[i-1][j-1]+1;
				} else {
					dp[i][j]=max(dp[i-1][j-1],max(dp[i-1][j],dp[i][j-1]));
				}
			}
		}
		int na=int(a.size());
		int nb=int(b.size());
		v.push_back(dp[na][nb]);
	}
	for (int i = 0; i < v.size(); ++i)
	{
		printf("%d\n",v[i]);
	}

	return(0);
}