Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}

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

C++: /* Dynamic Programming C/C++ implementation of LCS problem */
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int max(int a, int b);
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
int lcs( string X, string Y, int m, int n ) {
    int L[m + 1][n + 1];
    int i, j;
    /* Following steps build L[m+1][n+1] in bottom up fashion. Note
       that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1]*/

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

 //int index = L[m][n];

 /**if (index == 0) {printf("*"); return 0;}
 char lcs[index+1];
 lcs[index] = '\0'; // Set the terminating character

    // Start from the right-most-bottom-most corner and
    // one by one store characters in lcs[]
    i = m,
    j = n;
    while (i > 0 && j > 0 )
    {
        // If current character in X[] and Y are same, then
        // current character is part of LCS
        if (X[i-1] == Y[j-1])
        {
            lcs[index-1] = X[i-1]; // Put current character in result
            i--; j--; index--;     // reduce values of i, j and index
        }

            // If not same, then find the larger of two and
            // go in the direction of larger value
        else if (L[i-1][j] > L[i][j-1])
            i--;
        else
            j--;
    }

    printf("%s\n",lcs);**/

    /* L[m][n] contains length of LCS for X[0..n-1] and Y[0..m-1] */
    return L[m][n];
}

/* Utility function to get max of 2 integers */
int max(int a, int b) {
    return (a > b)? a : b; }

/* Driver program to test above function */
int main() {
    int N;
    scanf("%d",&N);
    for (int i = 0; i < N; i++) {
        int m ;
        int n ;
        string X;
        string Y;
        cin >> X >> Y;
        m = X.length();
        n = Y.length();
        cout << lcs(X, Y, m, n) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int A[1005][1005]={};

int main() {
  int i,j,k,q;
  cin >> q;
  string a,b;
  for(i=0;i<q;i++) {
    cin  >> a >> b;
    int al = a.size();
    int bl = b.size();
    for(j=1;j<=al;j++) {
      for(k=1;k<=bl;k++) {
        if(a[j]==b[k]) {
          A[j][k]=A[j-1][k-1]+1;
        } else {
          A[j][k]=max(A[j][k-1],A[j-1][k]);
        }
      }
    }
    cout << A[al][bl] << endl;
  }
  return 0;
}

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

using namespace std;

int main () {

    int N, m, n, i, j, k, c[1001][1001];
    string x, y;

    cin >> N;

    for (k = 0; k < n; k++) {
        cin >> x >> y;
        m = x.size ();
        n = y.size ();

        for (i = 1; i < m + 1; i++) {
            for (j = 1; j <= n + 1; j++) {

                if (x[i - 1] == y[j - 1]) {
                    c[i][j] = c[i - 1][j - 1] + 1;
                } else {
                    c[i][j] = max (c[i - 1][j], c[i][j - 1]);
                }

            }
        }

    cout << c[p][q] << endl;

    }

}