Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func lcs(a, b string) int {
	lenA := len(a)
	lenB := len(b)
	dp := make([][]int, lenA+1)
	for i := range dp {
		dp[i] = make([]int, lenB+1)
	}

	for i := 1; i <= lenA; i++ {
		for j := 1; j <= lenB; j++ {
			if a[i-1] == b[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = max(dp[i][j-1], dp[i-1][j])
			}
		}
	}
	return dp[lenA][lenB]
}

func main() {
	n := scanInt()
	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		a := scanString()
		b := scanString()
		fmt.Fprintln(w, lcs(a, b))
	}
	w.Flush()
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define NIL -1
using namespace std;

int count(const string& X, int i, const string Y, int j,
          vector<vector<int> >& MEMO){
    if (i >= X.size() || j >= Y.size()) return 0;
    if (MEMO[i][j] != NIL) return MEMO[i][j];
    int next_Y = count(X, i    , Y, j + 1, MEMO);
    int next_X = count(X, i + 1, Y, j    , MEMO);
    int max_ = max(next_Y, next_X);
    int j_tmp = j;
    while (X[i] != Y[j_tmp]) {
        j_tmp++;
        if (j_tmp >= Y.size()) return max_;
    }
    int saiyou = count(X, i + 1, Y, j_tmp + 1, MEMO) + 1;
    if (max_ < saiyou) max_ = saiyou;
    return MEMO[i][j] = max_;
}

int solve(const string& X, const string& Y) {
    int max = 0;
    vector<vector<int> > MEMO(X.size(), vector<int>(Y.size(), NIL));
    for (int i = 0; i < X.size(); i++) {
        int c = count(X, i, Y, 0, MEMO);
        if (c > max) max = c;
    }
    return max;
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        string X, Y;
        cin >> X >> Y;
        cout << solve(X, Y) << endl;
    }
    return 0;
}

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

int lcs(string& x, string& y)
{
    int i, j, m = x.length(), n = y.length();
    vector<vector<int> > c(m + 1, vector<int>(n + 1));
    x.insert(x.begin(), ' ');
    y.insert(y.begin(), ' ');
    for (i = 1; 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]);
        }
    }
    return c[m][n];
}

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

C++: #include<iostream>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
using namespace std;



int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string a, b;
		cin >> a >> b;
		if (a.size() < b.size())swap(a, b);
		
		int ans = 0;
		for (int k = 0; k < a.size(); k++)
		{
			for (int s = 0; s <= a.size() - b.size(); s++)
			{
				int sum = 0;
				for (int j = 0; j < b.size(); j++)
				{
					if (a[j + s] == b[j])sum++;
				}
				ans = max(sum, ans);
			}
		}
		cout << ans << endl;

		



	}



}

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

int lcs(string X, string Y){
    int C[1001][1001];
    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<=n; 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] = 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 <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
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 INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[30][51000];

int main(){
    ll q;
    cin>> q;
    string s[q],t[q];
    for (ll i=0;i<q;i++){
        cin >> s[i] >> t[i];
    }
    ll dp[1100][1100];
    memset(dp,0,sizeof(dp));
    for (ll i=0;i<q;i++){
        ll dp[1100][1100];
        memset(dp,0,sizeof(dp));
        for (ll j=0;j<s[i].size();j++){
            for (ll k=0;k<t[i].size();k++){
                if (s[i][j]==t[i][k]){
                    dp[j+1][k+1]=dp[j][k]+1;
                }else{
                    dp[j+1][k+1]=max(dp[j][k+1],dp[j+1][k]);
                }
            }
        }
        cout << dp[s[i].size()][t[i].size()] << endl;
    }
    return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N=55555;
bool is_prime[MAX_N];
int prime[MAX_N];
int main(){
  int n;
  cin>>n;
  int dp[1001][1001];
  for(int nn=0;nn<n;nn++){
    string s1,s2;
    cin>>s1>>s2;
    for(int i=0;i<1001;i++)fill(dp[i],dp[i]+1001,0);
    for(int i=0;i<s1.size();i++){
      for(int j=0;j<s2.size();j++){
        if(s1[i]==s2[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+1][j],dp[i][j+1]);
      }
    }
    cout<<dp[s1.size()][s2.size()]<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

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

int main() {
  int q;
  cin >> q;
  while(q--) {
    string x, y;
    cin >> x >> y;
    int dp[1001][1001];

    for(int i = 0; i < x.size(); i++) {
      dp[i][0] = 0;
    }
    for(int i = 0; i < y.size(); i++) {
      dp[0][i] = 0;
    }

    for(int i = 0; i < x.size(); i++) {
      for(int j = 0; j < y.size(); j++) {
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        if(x[i] == y[j]) {
          dp[i+1][j+1] = dp[i][j] + 1;
        }
      }
    }
    cout << dp[x.size()][y.size()] << endl;
  }
  return 0;
}