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 <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int N, M, K, Q, W, H, R, C;
int dp[1100][1100];

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

    cin >> Q;
    vector<int> ans;

    REP(i, Q) {
        string a, b;
        cin >> a >> b;
        memset(dp, 0, sizeof(dp));

        FOR(i, 1, (int)a.size() + 1) {
            FOR(j, 1, (int)b.size() + 1) {
                if (a[i - 1] == b[j - 1]) chmax(dp[i][j], dp[i - 1][j - 1] + 1);
                chmax(dp[i][j], dp[i - 1][j]);
                chmax(dp[i][j], dp[i][j - 1]);
            }
        }
        /*
        REP(i, (int)a.size() + 1) {
            REP(j, (int)b.size() + 1) { cout << dp[i][j] << " "; }
            cout << endl;
        }
        */
        ans.push_back(dp[(int)a.size()][(int)b.size()]);
    }

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

    return 0;
}

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

using namespace std;

int lcslen[1001][1001];
int compute_lcslen(const string &x,const string &y);

int main(){
  int q;
  cin >> q;
  for(int i=0;i<q;++i){
    string x,y;
    cin >> x;
    cin >> y;
    cout << compute_lcslen(x,y) << endl;
  }

  return 0;
}

int compute_lcslen(const string &x,const string &y){
  for(int i=1;i<=x.length();++i){
    for(int j=1;j<=y.length();++j){
      if(x[i]==y[j]){
        lcslen[i][j] = lcslen[i-1][j-1]+1;
      }else{
        lcslen[i][j] = max(lcslen[i-1][j],lcslen[i][j-1]);
      }
    }
  }
  return lcslen[x.length()][y.length()];
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#define MAX 1000

using namespace std;

string s,t;
int dp[MAX + 1][MAX + 1];

int LCS(void){

  for( int i = 0 ; i < s.size() ; i++ ){
    for( int j = 0 ; j < t.size() ; j++ ){
      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]);
      }
    }
  }
  return dp[s.size()][t.size()];
}


int main(void){

  int n;
  cin >> n;
  while(n--){

    memset(dp, 0 , sizeof(dp) );

    cin >> s >> t;
    cout << LCS() << endl;

  }
  return 0;
}

C++: #include <iostream>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int LCS(string s, string t);

int main(void){
  int n;
  string s;
  string t;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    cin>>t;
    cout<<LCS(s,t)<<endl;
  }
}

int LCS(string s, string t){
  int a[s.length()+1][t.length()+1];
  for(int i=0;i<s.length()+1;i++){
    for(int j=0;j<t.length()+1;j++){
      a[i][j]=0;
    }
  }
  char S,T;
  for(int i=1;i<s.length()+1;i++){
    for(int j=1;j<t.length()+1;j++){
      S=s[i-1];
      T=t[j-1];
      if(S!=T){
        a[i][j]=max({a[i-1][j-1],a[i-1][j],a[i][j-1]});
      }
      else{
        a[i][j]=max({a[i-1][j-1]+1,a[i-1][j],a[i][j-1]});
      }
    }
  }
  return a[s.length()][t.length()];
}

C++: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n;
    cin >>n;
    int a=0,b=0;
    string x,y;
    vector<vector<int>>dp(1010,vector<int>(1010,0));
    rep(_,n){
        rep(i,a+1){
            rep(j,b+1){
                dp[i][j]=0;
            }

        }
        cin>>x>>y;
        a=x.size();
        b=y.size();
       
        rep(i,a){
            rep(j,b){
                
                    chmax(dp[i+1][j+1],dp[i][j+1]);
                
                if(j!=0){
                    chmax(dp[i+1][j+1],dp[i+1][j]);
                }
                if(x[i]==y[j]){
                    chmax(dp[i+1][j+1],dp[i][j]+1);
                }
            }
        }
        cout<<dp[a][b]<<endl;
    }
    
}

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

const int MAX_N=1e3+5;

string s1,s2;

int dp[MAX_N][MAX_N];


int lcs(int i,int j){
	if(i==s1.size() || j==s2.size())return 0;
	if(dp[i][j]!=-1)return dp[i][j];
	if(s1[i]==s2[j])return dp[i][j]=lcs(i+1,j+1)+1;
	return dp[i][j]=max(lcs(i+1,j),lcs(i,j+1));
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		s1.clear();s2.clear();
		for(int j=0;j<MAX_N;j++)fill(dp[j],dp[j]+MAX_N,-1);
		cin>>s1>>s2;
		cout<<lcs(0,0)<<endl;
	}
}

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

int lcs(string &X, string &Y) {
  int dp[1000 + 1][1000 + 1];
  int max = 0;
  int m = X.size();
  int n = Y.size();
  X = ' ' + X;
  Y = ' ' + Y;

  for (int i = 1; i <= m; i++)
    dp[i][0] = 0;

  for (int i = 1; i <= n; i++)
    dp[0][i] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j])
	dp[i][j] = dp[i-1][j - 1] + 1;
      else if (dp[i - 1][j] >= dp[i][j - 1])
	dp[i][j] = dp[i - 1][j];
      else
	dp[i][j] = dp[i][j - 1];

      if(max < dp[i][j])
	max = dp[i][j];
    }
  }

  return max;
}

int main() {
  int N = 0;
  cin >> N;

  string X, Y;
  for (int i = 0; i < N; i++) {
    cin >> X >> Y;

    cout << lcs(X, Y) << endl;
  }

  return 0;
}