Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

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

int main(){
    int N;
    cin>>N;
    int ans[151];
    if(N>20){
        for(int i=0;i<N;i++){
            string inp1,inp2;
            cin>>inp1;
            cin>>inp2;
            int dp[101][101]={};
            for(int j=1;j<=inp1.size();j++){
                for(int k=1;k<=inp2.size();k++){
                    if(inp1[j-1]==inp2[k-1]){
                        dp[j][k]=dp[j-1][k-1]+1;
                    }else{
                        dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
                    }
                }
            }
            ans[i]=dp[inp1.size()][inp2.size()];
        }
    }else{
        for(int i=0;i<N;i++){
            string inp1,inp2;
            cin>>inp1;
            cin>>inp2;
            int dp[1001][1001]={};
            for(int j=1;j<=inp1.size();j++){
                for(int k=1;k<=inp2.size();k++){
                    if(inp1[j-1]==inp2[k-1]){
                        dp[j][k]=dp[j-1][k-1]+1;
                    }else{
                        dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
                    }
                }
            }
            ans[i]=dp[inp1.size()][inp2.size()];
        }
    }
    for(int i=0;i<N;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
int main()
{
  int n;
  int an[1000];
  int l=0;
  std::cin>>n;
  std::string x;
  std::string y;
  int ans[1001][1001];
  int j,k;
  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<=1000;j++){
      for(int k=0;k<=1000;k++){
	ans[j][k]=0;
      }
    }
    for(int j=1;j<x.size()+1;j++){
      for(int k=1;k<y.size()+1;k++){
	if(x[j-1]==y[k-1]){
	  ans[j][k]=ans[j-1][k-1]+1;
	}else{
	  if(ans[j][k-1]>ans[j-1][k]){
	    ans[j][k]=ans[j][k-1];
	  }else{
	    ans[j][k]=ans[j-1][k];
	  }
	}
      }
    }
    std::cout<<ans[x.size()][y.size()]<<'\n';  
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <memory.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    int Q;
    string X, Y;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        cin >> X >> Y;
        int DP[1001][1001];
        memset(DP, 0, sizeof(DP));
        for (int sx = 1; sx <= X.size(); ++sx) {
            for (int sy = 1; sy <= Y.size(); ++sy) {
                DP[sx][sy] = max(DP[sx][sy-1], DP[sx][sy-1]);
                if (X[sx] == Y[sy]) {
                    DP[sx][sy] = max(DP[sx][sy], DP[sx-1][sy-1]+1);
                }
            }
        }
        cout << DP[X.size()][Y.size()] << 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], maxl = 0, i, j;
  int m = x.size();
  int n = y.size();

  x = ' ' + x;
  y = ' ' + y;
 
  for(i = 1; i <= m; i++) c[i][0] = 0;
  for(i = 0; i <= n; i++) c[0][i] = 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 - 1][j], c[i][j - 1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

int main(){
  string x, y;
  int q, i;

  cin >> q;
  
  for(i = 0; i < q; i++){
    cin >> x >> y;
    cout << lcs(x, y) << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int lcs(string x, string y) {
  vector<vector<int> > dp(x.size() + 1, vector<int>(y.size() + 1));
  int xl = x.size();
  int yl = y.size();
  int maxl = 0;
  x = ' ' + x;
  y = ' ' + y;

  for (int i = 0; i <= xl; i++) {
    dp[i][0] = 0;
  }
  for (int j = 1; j <= yl; j++) {
    dp[0][j] = 0;
  }

  for (int i = 1; i <= xl; i++) {
    for (int j = 1; j <= yl; 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]);
      }
      maxl = max(maxl, dp[i][j]);
    }
  }
  return maxl;
}

int main() {
  int q;
  cin >> q;
  string x, y;
  rep(i, q) {
    cin >> x >> y;
    cout << lcs(x, y) << endl;
  }
  return 0;
}

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

int CS(string a, int lena, string b, int lenb)
{
    int ret;

    if ((lena > 0) && (lenb > 0)) {
        if (a[lena] == b[lenb]) {
            ret = CS(a, lena - 1, b, lenb - 1) + 1;
        }
        else {
            ret = max(CS(a, lena, b, lenb - 1), CS(a, lena - 1, b, lenb));
        }
    }
    else {
        ret = 0;
    }

    return ret;
}

int LCS(string a, string b)
{
    int ret;
    int len1, len2;

    len1 = a.length();
    len2 = b.length();
    ret  = CS(a, len1, b, len2);

    return ret;
}

int main(void)
{
    int i;
    int num;
    int ret;
    string a, b;

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        cin >> a;
        cin >> b;
        ret = LCS(a, b);
        printf("%d\n", ret);
    }

    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
  char str1[1000],str2[1000];
  int LCS[1000][1000]={0};
  int length1,length2;
  int n;
  ios::sync_with_stdio(false);
  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;
}