Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 1001

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func lcs(x, y string) int {
	var c [N][N]int
	m := len(x)
	n := len(y)
	var maxl int

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

	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])
			}
			maxl = max(maxl, c[i][j])
		}
	}
	return maxl
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	var out bytes.Buffer
	for i := 0; i < q; i++ {
		sc.Scan()
		s1 := sc.Text()
		sc.Scan()
		s2 := sc.Text()
		out.WriteString(fmt.Sprintf("%d\n", lcs(s1, s2)))
	}
	return strings.TrimRight(out.String(), "\n")
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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

using namespace std;
const int L = 1001;
const int INF = -1001001001;

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

C++: #include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
#define MAX_q 150
#define MAX_L 1000
string X, Y;
int dp[MAX_L + 1][MAX_L + 1];
void DP() {
    rep(i, X.size()) {
        rep(k, Y.size()) { dp[i][k] = 0; }
    }
    rep(i, X.size()) {
        rep(k, Y.size()) {
            if (X[i] == Y[k]) {
                dp[i + 1][k + 1] = dp[i][k] + 1;
            } else {
                dp[i + 1][k + 1] = max(dp[i][k + 1], dp[i + 1][k]);
            }
        }
    }
}
int main() {
    int q;
    cin >> q;
    rep(j, q) {
        cin >> X >> Y;
        DP();
        cout << dp[X.size()][Y.size()] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[1001][1001];




	
int main (){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	//input
	int n;
	cin >> n;
	vector<string> S(n);
	vector<string> T(n);
	for(int i=0;i<n;i++)cin >> S[i] >> T[i];


	//alorithm
	for(int i=0;i<n;i++){
		string s,t;
		s=S[i];
		t=T[i];
		memset(dp,0,sizeof(dp));
		for(int i=1;i<=s.size();i++){
			for(int j=1;j<=t.size();j++){
				if(s[i-1]==t[j-1]){dp[i][j]=dp[i-1][j-1]+1;continue;}
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
		cout << dp[s.size()][t.size()] << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;

void print() { cout << endl; }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
    int size = sizeof...(Tail);
    cout << head;
    if (size > 0) {
        cout << " ";
    }
    print(tail...);
}

void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
    cout << head;
    print0(tail...);
}

struct xstruct {
    ll val;
};
bool operator<=(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val <= rhs.val;
}
bool operator<(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val < rhs.val;
}
bool operator>=(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val >= rhs.val;
}
bool operator>(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val > rhs.val;
}
bool operator==(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val == rhs.val;
}
bool operator!=(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val != rhs.val;
}
ostream& operator<<(ostream& os, xstruct const& xst) {
    return os << xst.val;
}

ll recursive(ll a, ll b, string& sa, string& sb, vector<vector<ll>>& dp) {
    ll maxval = 0;
    if (a == sa.length() || b == sb.length()) {
        return maxval;
    }
    if (dp[a][b] >= 0) {
        return dp[a][b];
    }

    if (sa.at(a) == sb.at(b)) {
        maxval = max(maxval, 1 + recursive(a + 1, b + 1, sa, sb, dp));
    }
    maxval = max(maxval, recursive(a + 1, b, sa, sb, dp));
    maxval = max(maxval, recursive(a, b + 1, sa, sb, dp));
    dp[a][b] = maxval;
    return dp[a][b];
}

int main() {
    ll N = 0;
    cin >> N;
    string nil;
    getline(cin, nil);
    for (ll iter = 0; iter < N; iter++) {
        string sa, sb;
        getline(cin, sa);
        getline(cin, sb);
        ll la = sa.length();
        ll lb = sb.length();

        vector<vector<ll>> dp(la, vector<ll>(lb));
        for (ll a = 0; a < la; a++) {
            for (ll b = 0; b < lb; b++) {
                dp[a][b] = -1;
            }
        }
        recursive(0, 0, sa, sb, dp);
        print(dp[0][0]);
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
using namespace std;
//using ll = long long;
//const ll mod = 1000000007;
int n, m;
string s, t;
const int n_max = 1000;
const int m_max = 1000;

int main() {
	cin >> n;
	for(int k=0; k<n; ++k){
        cin >> s >> t;
        int dp[n_max+1][m_max+1] = {0};
	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]);
			}
		}
	}
        cout << dp[s.size()][t.size()] << endl;
    }
	

	return 0;
}

C++: //#include "aizu.h"
#include <iostream>
#include <string>
#include <vector>

//namespace alds1_10_c{
template<class T>
T myMin(const T& arg){
	return arg;
}
template<class F, class... S>
F myMin(const F& first, const S&... second){
	F m = myMin(second...);
	if (m > first){
		return first;
	}else{
		return m;
	}
}
int f(std::string::iterator str1, const std::string& str2, const std::vector<int>& vec){
	std::vector<int> new_v;
	new_v.push_back(vec[0] + 1);
	{
		auto v = vec.begin() + 1;
		for (auto i = str2.begin(); i != str2.end(); ++i, ++v){
			if (*i == *str1){
				new_v.push_back(myMin(*v, *(v - 1), new_v.back()));
			}else{
				new_v.push_back(myMin(*v + 1, new_v.back() + 1));
			}
		}
	}
	if (*(++str1) != '\0'){
		return f(str1, str2, new_v);
	}else{
		return new_v.back();
	}
}
int main(){
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i){
		std::string str1, str2;
		std::cin >> str1 >> str2;
		std::vector<int> vec;
    vec.push_back(0);
		for (int j = 0; j < str2.size(); ++j){
			vec.push_back(j);
		}
		std::cout << (str1.size() + str2.size() - f(str1.begin(), str2, vec)) / 2 << "\n";
	}
}
//}