Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func f() {
	var S, T string
	fmt.Scan(&S)
	fmt.Scan(&T)
	lenS, lenT := len(S), len(T)
	dp := make([][]int, lenS+1)
	for i:=0; i<lenS+1; i++ {
		dp[i] = make([]int, lenT+1)
	}
	for i:=1; i<lenS+1; i++ {
		for j:=1; j<lenT+1; j++ {
			if S[i-1] == T[j-1] {
				dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
		}
	}
	fmt.Println(dp[lenS][lenT])
}

func main(){
	var n int 
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		f()
	}
}

C++: #include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define Rep(i,n) REP(i,0,n)
typedef long long ll;

int q;
string X,Y;
int c[1003][1003];


int main(){
    cin>>q;
    Rep(i,q){
        cin>>X>>Y;
        int m,n;
        int maxl=0;
        m=X.size();
        n=Y.size();
        Rep(j,m+1) c[j][0]=0;
        Rep(k,n+1) c[0][k]=0;
        REP(j,1,m+1){
            REP(k,1,n+1){
                if(X[j]==Y[k]) 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]);
            }
        }
        cout<<maxl<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
static const int N = 1000;
 
int las(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 mail;
}
 
int main() {
string s1, s2;
int n; cin >> n;
for ( int i = 0; i < n; i++ ) {
cin >> s1 >> s2;
cout << les(s1, s2) << endl;
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib> 
using namespace std;
static const int N = 1000;

int lcs(string X,string Y){
	int **c=(int **)malloc(sizeof(int *)*1001);
	for(int i=0;i<1001;i++){
		c[i]=(int *)malloc(sizeof(int)*1001);
	}
	int m=X.size();
	int n=Y.size();
	int maxl=0;
	X=' '+X;
	Y=' '+Y;
	c[0][0]=0;
	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 <iostream>
#include <cstring>

using namespace std;

int main(void)
{
    int q;
    char x[1001], y[1001];
    int table[1001][1001];
    
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> x >> y;
        int xl = strlen(x), yl = strlen(y);

        for (int i = 0; i < xl; i++)
            for (int j = 0; j < yl; j++)
                if (x[i] == y[j])
                    table[i+1][j+1] = 1 + table[i][j];
                else
                    table[i+1][j+1] = max(table[i][j+1], table[i+1][j]);

        cout << table[xl][yl] << endl;
    }

    return 0;
}

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

int dp[1001][1001];
int main() {
    int q;
    cin>>q;
    int ans[150] = {0};
    for (int i = 0; i < q; ++i) {
        memset(dp, 0, sizeof(dp));
        string x, y;
        cin>>x>>y;
        int xlen = x.length();
        int ylen = y.length();
        for(int ix = 0; ix < xlen; ++ix) {
            for(int iy = 0; iy < ylen; ++iy) {
                if (x[ix] == y[iy]) {
                    dp[ix + 1][iy + 1] = max(max(dp[ix][iy] + 1, dp[ix + 1][iy]), dp[ix][iy+1]);
                } else {
                    dp[ix + 1][iy + 1] = max(dp[ix + 1][iy], dp[ix][iy+1]);
                }
            }
        }
        ans[i] = dp[xlen][ylen];
    }

    for(int i = 0; i < q; ++i) {
        cout<<ans[i]<<endl;
    }

}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
int main(){
    int q;
    scanf("%d",&q);
    string x,y;
    REP(i,q){
        cin>>x>>y;
        int dp[x.size()+1][y.size()+1];
        fill(dp[0],dp[x.size()],-1);
        REP(j,x.size()+1) dp[j][0]=0;
        REP(j,y.size()+1) dp[0][j]=0;
        FOR(j,1,x.size()+1){
            FOR(k,1,y.size()+1){
                if(x[j-1]==y[k-1]) dp[j][k]=dp[j-1][k-1]+1;
                else dp[j][k]=max(dp[j][k-1],dp[j-1][k]);
            }
        }
        printf("%d\n",dp[x.size()][y.size()]);
    }
    return 0;
}

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

#define N 1000

int lcs(std::string x, std::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 i = 0; i <= m; i++) c[0][i] = 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] = std::max(c[i - 1][j], c[i][j - 1]);
			maxl = std::max(maxl, c[i][j]);
		}
	}
	return maxl;
}

int main() {
	std::string s1, s2;
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> s1 >> s2;
		std::cout << lcs(s1, s2) << std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
#include <inttypes.h>

int LCS(std::string s, std::string t){
    int n, m, c[1001][1001] = {0};
    n = s.size();
    m = t.size();
    int maxlen = 0;
    for(int i = 1; i <= n; i++){
        c[i][0] = 0;
    }
    for(int i = 1; i <= m; i++){
        c[0][i] = 0;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i - 1] == t[j - 1]){
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else{
                c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
            }
            maxlen = std::max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}
int main(){
    int N;

    std::cin >> N;
    std::string s1, s2;
    for(int i = 0; i<N; i++){
        std::cin >> s1 >> s2;
        std::cout << LCS(s1, s2) << std::endl;
    }
    return 0;
}