Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

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

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

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

int main(){
	
	vector<int> v;
	int n=0;
	scanf("%d", &n);
	string a;
	string b;
	for (int i = 0; i < n; ++i)
	{
		char a1[1000],b1[1000];
		string a(a1);
		string b(b1);
		vector<vector<int> > dp(int(a.size()), vector<int>(int(b.size())));
		
		if(a[0]==b[0]) dp[0][0]=1;
		for (int i = 0; i < a.size(); ++i)
		{
			if(a[i]==b[0]){
				dp[i][0]=1;
			} else {
				dp[i][0]=dp[i-1][0];
			}
		}
		for (int i = 0; i < b.size(); ++i)
		{
			if(a[0]==b[i]){
				dp[0][i]=1;
			} else {
				dp[0][i]=dp[0][i-1];
			}
		}
		for (int i = 1; i < a.size(); ++i)
		{
			for (int j = 1; j < b.size(); ++j)
			{
				if(a[i]==b[j]){
					dp[i][j]=dp[i-1][j-1]+1;
				} else {
					dp[i][j]=max(dp[i-1][j-1],max(dp[i-1][j],dp[i][j-1]));
				}
			}
		}
		int na=int(a.size());
		int nb=int(b.size());
		v.push_back(dp[na][nb]);
	}
	for (int i = 0; i < v.size(); ++i)
	{
		printf("%d\n",v[i]);
	}

	return(0);
}

C++: #include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string str1,str2;
        cin>>str1>>str2;
        int lenth1,lenth2;
        lenth1=(int)str1.length();
        lenth2=(int)str2.length();
        int dp[lenth1+1][lenth2+1];
        for(int j=0;j<=lenth1;j++)dp[j][0]=0;
        for(int j=0;j<=lenth2;j++)dp[0][j]=0;
        for(int j=1;j<=lenth1;j++)
        {
            for(int k=1;k<=lenth2;k++)
            {
                if(str1[j-1]==str2[k-1])
                {
                    dp[j][k]=dp[j-1][k-1]+1;
                }
                else dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
            }
        }
        cout<<dp[lenth1][lenth2]<<endl;
    }
    return 0;
}

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

int lcs(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 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 <string>
using namespace std;

int lcs(string X, string Y) {
  int cs[1000][1000];
  int m = X.size();
  int n = Y.size();
  int answer = 0;
  for (int i = 0; i < m; i++) cs[m][0] = 0;
  for (int i = 0; i < n; i++) cs[0][n] = 0;

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (X[i] == Y[j]) {
        cs[i][j] = 1 + cs[i - 1][j - 1];
      } else {
        cs[i][j] = max(cs[i - 1][j], cs[i][j - 1]);
      }
      answer = max(answer, cs[i][j]);
    }
  }

  return answer;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  string X, Y;
  for (int i = 0; i < n; i++) {
    cin >> X >> Y;
    cout << lcs(X, Y) << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T>
T chmin(T &a, T b){
    if(a > b){ a=b; return true;}
    return false;
}

template<typename T>
T chmax(T &a, T b){
    if(a < b){ a=b; return true;}
    return false;
}

int main(){
    int q; cin >> q;
    while(q--){
        string X, Y;
        cin >> X >> Y;

        vii dp(X.size()+1, vi(Y.size()+1, 0));
        for(int i=0; i<X.size(); i++){
            for(int j=0; j<Y.size(); j++){
                if(X[i] == Y[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
                chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
            }
        }

        cout << dp[X.size()][Y.size()] << endl;
    }
    return 0;
}

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

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";
	}
}