Go: package main

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

const max int = 1000 + 1
var A [][]int

func lcs(x, y string) int {
	x = " " + x
	y = " " + y
	for i:=0;i<len(x); i++ {
		for j:=0;j<len(y); j++ {
			A[i][j] = 0
		}
	}
	for i:=1; i<len(x); i++ {
		for j:=1; j<len(y); j++ {
			if x[i] == y[j] {
				A[i][j] = A[i-1][j-1] + 1
			} else if A[i-1][j] > A[i][j-1] {
				A[i][j] = A[i-1][j]
			} else {
				A[i][j] = A[i][j-1]
			}
		}
	}
	return A[len(x)-1][len(y)-1]
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num 
}

func nextStr(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}


func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	A = make([][]int, max)
	for i := range A {
		A[i] = make([]int, max)
	}
	n := nextInt(scanner)
	for i:=0; i<n; i++ {
		x := nextStr(scanner)
		y := nextStr(scanner)
		fmt.Printf("%d\n", lcs(x, y))
	}
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

const int MAX_SIZE = 52;

int LCS(const char* a, const char* b){
    int n = 0, m = 0;
    vector<int> x,y;
    for(;a[n] != '\0';n++){
        int s = a[n]-'a';
        if(s < 0){
            s = a[n]-'A'+26;
        }
        x.pb(s);
    }
    for(;b[m] != '\0';m++){
        int s = b[m]-'a';
        if(s < 0){
            s = b[m]-'A'+26;
        }
        y.pb(s);
    }
    vector<vector<int> > vec(MAX_SIZE);
    for(int j = m-1; j >= 0; --j){
        vec[y[j]].push_back(j);
    }
    vector<int> xs(n+1, INF);
    xs[0] = -INF;
    vector<P> nx(n+1,P(-INF,-INF));
    rep(i,n){
        vector<int>& ys = vec[x[i]];
        rep(j,(int)ys.size()){
            int k = lower_bound(xs.begin(),xs.end(),ys[j]) - xs.begin();
            xs[k] = ys[j];
            nx[k] = P(y[ys[j]], k-1);
        }
    }
    return lower_bound(xs.begin(),xs.end(),INF-1) - xs.begin() - 1;
}


int main()
{
    int q;
    scanf("%d",&q);
    rep(i,q){
        char x[1000], y[1000];
        scanf("%s%s",x,y);
        cout << LCS(x,y) << "\n";
    }
    return 0;
}

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

using namespace std;

array< array<int, 50001>, 20> dp{{}};
array<int, 20> denominations;

int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int coin;
        cin >> coin;
        denominations[i] = coin;
    }
    sort(begin(denominations), begin(denominations) + m);
    iota(begin(dp[0]), end(dp[0]), 0);
    
    for (int row = 1; row < m; ++row) {
        for (int col = 1; col <= n; ++col) {
            int coin = denominations[row];
            int use_coin, dont_use_coin;
            if (col >= coin) {
                use_coin = 1 + dp[row-1][col-coin];
            }
            dont_use_coin = dp[row-1][col];
            dp[row][col] = col >= coin ?
                min(use_coin, dont_use_coin) :
                dont_use_coin;
        }
    }
    cout << dp[m-1][n] << endl;
}

C++: #include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int solve(string x, string y)
{
    vector<vector<int> > c(x.size(), vector<int>(y.size(), 0));

    if (x[0] == y[0]) {
        c[0][0] = 1;
    }

    for (int i = 1; i < x.size(); i++) {
        if (c[i - 1][0] == 1 || x[i] == y[0]) {
            c[i][0] = 1;
        } else {
            c[i][0] = 0;
        }
    }
    for (int i = 1; i < y.size(); i++) {
        if (c[0][i - 1] == 1 || x[0] == y[i]) {
            c[0][i] = 1;
        } else {
            c[0][i] = 0;
        }
    }

    for (int i = 1; i < x.size(); i++) {
        for (int j = 1; j < y.size(); 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]);
            }
        }
    }

    return c[x.size() - 1][y.size() - 1];
}

int main()
{
    int q;
    cin >> q;

    vector<string> x(q), y(q);
    for (int i = 0; i < q; i++) {
        cin >> x[i] >> y[i];
    }
    for (int i = 0; i < q; i++) {
        cout << solve(x[i], y[i]) << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int L[1001][1001];
int main(){
    int N;
    string X,Y;
    cin >>N;
    for(int k=0;k<N;++k){
        cin>>X>>Y;
        for(int i=1;i<X.length()+1;++i){
            for(int j=1;j<Y.length()+1;++j){
                if(X[i]==Y[j]){
                    L[i][j]=L[i-1][j-1]+1;
                }
                else
                    L[i][j]=max(L[i-1][j],L[i][j-1]);
                
            }
        }
        cout<<L[X.length()][Y.length()]<<endl;
    }
    return 0;
}

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

int main(){
  int n;
  char x[1000],y[1000];
  int dp[1001][1001];
  //load n;
  cin >>n;
  for(int i=0;i<n;i++){
    //load string
    scanf("%s",x);
    scanf("%s",y);
    //dp
    for(int j=0;j<strlen(x);j++){
      for(int k=0;k<strlen(y);k++){
	if(x[j]==y[k]){
	  dp[j+1][k+1]=dp[j][k]+1;
	}

	else{
	  if(dp[j][k+1]>dp[j+1][k]){
	    dp[j+1][k+1]=dp[j][k+1];
	  }

	  else{
	    dp[j+1][k+1]=dp[j+1][k];
	  }


	}
      }
    }
    cout <<dp[strlen(x)][strlen(y)]<<endl;
  }



  return 0;
}

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

#define N 1001
int A[N][N];

int main() {
    int q;
    cin >> q;

    string target1;
    string target2;
    for (int i = 0; i < q; i++) {
        cin >> target1;
        cin >> target2;
        int l1 = target1.length();
        int l2 = target2.length();
        for (int m = 0; m <= l1; m++) {
            A[m][0] = 0;
        }
        for (int n = 0; n <= l2; n++) {
            A[0][n] = 0;
        }

        target1 = ' ' +  target1;
        target2 = ' ' +  target2;

        for (int m = 1; m <= l1; m++) {
            for (int n = 1; n <= l2; n++) {
                if (target1[m] == target2[n]) {
                    A[m][n] = A[m-1][n-1] + 1;
                } else {
                    A[m][n] = max(A[m-1][n], A[m][n-1]);
                }
            }
        }

        cout << A[l1][l2] << endl;
    }

    return 0;
}