Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

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

using namespace std;

int main(void){
    int num;
    cin>>num;
    
    vector<vector<string>> inputData(num,vector<string>(2));

    int p=0;
    while(p<num){
        for(int i=0;i<2;i++){
            cin>>inputData[p][i];
        }
        p+=1;
    }

    int q=0;
    while(q!=num){
        int s=inputData[q][0].length();
        int t=inputData[q][1].length();
        vector<vector<int>> Table(s,vector<int>(t));

        for(int i=0;i<s;i++){
            if(inputData[q][0][0]==inputData[q][1][i]){
                Table[0][i]=1;
            }else{
                Table[0][i]=0;
            }

            if(inputData[q][0][i]==inputData[q][1][0]){
                Table[i][0]=1;
            }else{
                Table[i][0]=0;
            }
        }

        vector<int> RMax(t);
        for(int i=0;i<t;i++){
            RMax[i]=Table[0][i];
        }

        //Table作成
        for(int i=1;i<s;i++){
            int max=0;
            for(int j=1;j<t;j++){
                if(RMax[j-1]>max){
                    max=RMax[j-1];
                }
                Table[i][j]=max;
                if(inputData[q][0][i]==inputData[q][1][j]){
                    Table[i][j]+=1;
                }
            }

            for(int k=0;k<t;k++){
                if(Table[i][k]>RMax[k]){
                    RMax[k]=Table[i][k];
                }
            }
        }

        //表示
        int ans=0;
        for(int i=0;i<s;i++){
            for(int j=0;j<t;j++){
                if(Table[i][j]>ans){
                    ans=Table[i][j];
                }
            }
        }

        cout<<ans<<endl;

        // for(int i=0;i<s;i++){
        //     for(int j=0;j<t;j++){
        //         cout<<Table[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        q+=1;
        // cout<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF INT_MAX

string x, y;
vector < vector<int> > memo;

int lcs(int xs, int ys)
{
    if (xs == 0 || ys == 0) return 0;
    if (memo[xs][ys]) return memo[xs][ys];

    int res;
    if (x[xs-1] == y[ys-1]) {
        res = lcs(xs-1, ys-1) + 1;
    } else {
        res = max(lcs(xs,ys-1), lcs(xs-1,ys));
    }
    memo[xs][ys] = res;
    return res;
}

int main(int, char**)
{
    int q;
    cin >> q;

    vector<int> ans;
    rep(i,q) {
        cin >> x >> y;
        int xs = x.size();
        int ys = y.size();
        memo.assign(xs+1, vector<int>(ys+1,0));
        ans.push_back(lcs(xs,ys));
    }

    rep(i,q) cout << ans[i] << endl;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

string A,B;

ll dp[1007][1007];

int LCS(string A,string B){
    REP(i,1,A.size()+1){
        REP(j,1,B.size()+1){
            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]);
            }
        }
    }
    return dp[A.size()][B.size()];
}

int main(){
    ll N;cin>>N;
    rep(i,N){
        cin>>A>>B;
        cout << LCS(A,B) << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int dp[1001][1001];

int lcs(string x, string y)
{	
	int n = x.size();
	int m = y.size();

	x = " " + x;
	y = " " + y;

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

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; 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]);
			}
		}
	return dp[n][m];
}

int main()
{
	int q;
	string s1, s2;
	cin >> q;

	for (int i = 0; i < q; i++) {		
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}

	return 0;
}