Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int q;
    int dp[1005][1005];
    dp[0][0]=0;
    cin>>q;
    rep(z,q){
	string a,b;
	cin>>a>>b;
	
	reps(i,a.size()){
	    reps(j,b.size()){
		if(a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
		else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	    }
	}
	cout<<dp[a.size()][b.size()]<<'\n';
    }
				  
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int q;
  cin>>q;
  string a,b;
  int x[1001][1001];
  x[0][0]=0;
  for(int i=1;i<=1000;i++){
    x[0][i]=0;
    x[i][0]=0;
  }
  for(int i=0;i<q;i++){
    cin>>a>>b;
    for(int j=1;j<=a.size();j++){
      for(int l=1;l<=b.size();l++){
	if(a[j-1]==b[l-1]){
	  if(x[j-1][l-1]+1>x[j][l-1]){
	    x[j][l]=x[j-1][l-1]+1;
	  }else{
	    x[j][l]=x[j][l-1];
	  }
	}else{
	  if(x[j-1][l-1]>x[j][l-1]){
	    x[j][l]=x[j-1][l-1];
	  }else{
	    x[j][l]=x[j][l-1];
	  }
	}
      }
    }
    cout<<x[a.size()][b.size()]<<endl;
  }
  return(0);
}

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

using namespace std;

int lcs (string x, string y) {

    int m, n, c[1001][1001], i, j, maxl = 0;

    m = x.size();
    n = y.size();

    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 - 1][j], c[i][j - 1]);
                }

                maxl = max (maxl, c[i][j]);

            }
    }

    return maxl;

}



int main () {

    int N, i;
    string x, y;

    cin >> N;

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

    }

    return 0;

}

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

int a[1001][1001] = {0};

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

C++: #include<bits/stdc++.h>
using namespace std;
static const int N=1001;
int lcs(string X,string Y){
  int c[N+1][N+1];
  int m=X.size();
  int n=Y.size();

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

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>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9 + 7;
const ll LINF = 1LL << 60;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

int q;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> q;
  rep(qi,q) {
    string x, y;
    cin >> x >> y;
    int n = x.size(), m = y.size();
    vector<vector<int>> dp(n+10, vector<int>(m+10, 0));
    rep(i,n) rep(j,m) {
      if(x[i] == y[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
      else {
        chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
      }
    }
    cout << dp[n][m] << '\n';
  }
  return 0;
}

C++: #include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
const int MOD=1e9+7;

int main(){
  ll u;cin>>u;
  rep(k,0,u){

  string x,y;cin>>x>>y;
  ll n=x.size(),m=y.size();
  vvll dp(n+1,vll(m+1,0));
  
  rep(i,0,n){
    rep(j,0,m){
      if(x[i]==y[j])dp[i+1][j+1]=max(dp[i][j]+1,max(dp[i][j+1],dp[i+1][j]));
      else{dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);}
    }
  }
  
  cout<<dp[n][m]<<endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int c[1010][1010];
int lcs(string x,string y){
    int m = x.size();
    int n = y.size();
    int maxl;
    for (int i=1; i<=m; i++) {
        c[i][0] = 0;
    }
    for(int j=1;j<=n;j++){
        c[0][j] = 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(){
    int q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}