Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				} else {
					dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				}
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

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;

    }

}