Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	results := []int{}
	for i := 0; i < n; i++ {
		results = append(results, resolveInstance())
	}
	for _, v := range results {
		fmt.Println(v)
	}
	return
}

func resolveInstance() int {
	x, y := scanString(sc), scanString(sc)
	lx, ly := len(x), len(y)
	dp := make([][]int, lx+1)
	dp[0] = make([]int, ly+1)
	for i := 1; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
		dp[i][0] = dp[i-1][0]
		for j := 1; j <= ly; j++ {
			dp[i][j] = dp[i-1][j]
			if dp[i][j] < dp[i][j-1] {
				dp[i][j] = dp[i][j-1]
			}
			if x[i-1] == y[j-1] {
				cL := dp[i-1][j-1] + 1
				if dp[i][j] < cL {
					dp[i][j] = cL
				}
			}
		}
	}
	return dp[lx][ly]
}

const (
	remove = 0 + iota
	match
)

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

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;

    }

}