Go: package main

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

var (
	nstr   func() string
	stdout *bufio.Writer
)

func init() {
	nstr = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func main() {
	defer stdout.Flush()

	n := nint()
	xList := make([]string, n)
	yList := make([]string, n)

	for i:=0;i<n ;i++  {
		xList[i] = nstr()
		yList[i] = nstr()
	}

	for i := 0; i<n	; i++  {
		fmt.Println(lcs(xList[i], yList[i]))
	}

}

func lcs(x string, y string) int{
	var m = len(x)
	var n = len(y)

	c := make([][]int, m+1)
	for i:= range c{
		c[i] = make([]int, n+1)
	}
	for i:=	1;i<=m ;i++  {
		for j:=1;j<=n ;j++  {
			if x[i-1] == y[j-1]{
				c[i][j] = c[i-1][j-1] + 1
			}else{
				c[i][j] = int(math.Max(float64(c[i-1][j]), float64(c[i][j-1])))
			}


		}
	}
	return c[m][n]

}


func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func nint64() int64 {
	i, err := strconv.ParseInt(nstr(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func nint() int {
	return int(nint64())
}

func getIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nint()
	}
	return b
}

func getStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = nstr()
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2)
	} else {
		return strconv.FormatInt(i64, 2)
	}
}

func strReverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

C++: #include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>
#include <vector>
#include <memory>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG


vector<string> makeSubsequences(string str, int length)
{
  if (length == 0)
    return vector<string>();

  DPRINTF("str %s  length %d\n", str.c_str(), length);
  assert(0 <= length && length <= str.length());

  vector<string> subsequences;

  if (length == 1)
  {
    for (int i = 0; i < str.length(); i++)
    {
      subsequences.push_back(str.substr(i, 1));
    }

    return subsequences;
  }

  for (int i = 0; i <= str.length() - length; i++)
  {
    const string substr = str.substr(i + 1, str.length() - (i + 1));
    vector<string> strs = makeSubsequences(substr, length - 1);

    for (string s : strs)
      subsequences.push_back(str[i] + s);
  }

  return subsequences;
}


bool isFindSubseq(string str, string subseq)
{
  DPRINTF("str %s  subseq %s\n", str.c_str(), subseq.c_str());

  assert(str.length() > 0 && subseq.length() > 0);

  int j = 0;

  for (int i = 0; i < str.length(); i++)
  {
    if (str[i] == subseq[j])
      j++;

    if (j == subseq.length())
      return true;
  }

  return false;
}


int setLCSlen(string strShort, string strLong, int idx, int *pLength)
{
  DPRINTF("strLong %s  strShort %s  idx %d\n", strLong.c_str(), strShort.c_str(), idx);

  assert(strShort.length() && strLong.length() && idx >= 0 && pLength);

  if (idx == 0)
  {
    const string s = strShort.substr(0, 1);

    if (isFindSubseq(strLong, s))
      pLength[0] = 1;
    else
      pLength[0] = 0;

    return pLength[0];
  }

  if (!pLength[idx-1])
    setLCSlen(strShort, strLong, idx-1, pLength);

  const string sub = strShort.substr(0, idx);

  vector<string> candidates = makeSubsequences(sub, pLength[idx-1]);

  for (string &s : candidates)
    s = s + strShort[idx];

#if DEBUG
  DPRINTF("Candidates\n");
  for (string s : candidates)
    DPRINTF(" - %s\n", s.c_str());
#endif // DEBUG

  for (string s : candidates)
  {
    if (isFindSubseq(strLong, s))
    {
      pLength[idx] = s.length();
      break;
    }
  }

  if (!pLength[idx])
    pLength[idx] = pLength[idx-1];

  DPRINTF("pLength[%d] %d\n", idx, pLength[idx]);

  return pLength[idx];
}


int getLCSlen(string s0, string s1)
{
  const string* pStrLong;
  const string* pStrShort;

  if (s0.length() < s1.length())
  {
    pStrShort = &s0;
    pStrLong = &s1;
  }
  else
  {
    pStrShort = &s1;
    pStrLong = &s0;
  }

  int *pLongestLens = new int[pStrShort->length()];

  // init
  for (int i = 0; i < pStrShort->length(); i++)
    pLongestLens[i] = 0;

  const int longest = setLCSlen(*pStrShort, *pStrLong, pStrShort->length() - 1, pLongestLens);

  delete [] pLongestLens;

  return longest;
}


int main()
{
  int numOfPair;
  cin >> numOfPair; cin.ignore();

  DPRINTF("num of pair %d\n", numOfPair);

  for (int i = 0; i < numOfPair; i++)
  {
    string str0, str1;
    cin >> str0 >> str1; cin.ignore();

    DPRINTF("str0 %s  str1 %s\n", str0.c_str(), str1.c_str());

    cout << getLCSlen(str0, str1) << endl;
  }

  return 0;
}

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

int C[1001][1001];
string N1, N2;

int lcs()
{
	int m = N1.size();
	int n = N2.size();
	int maxl = 0;

	N1 = " " + N1;
	N2 = " " + N2;

	for (int i = 1; i <= m; i++)
		C[i][0] = 0;
	for (int i = 1; i <= n; i++)
		C[0][i] = 0;

	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (N1[i] == N2[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()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int q;

	cin >> q;
	for (int i = 0; i < q; i++)
	{
		cin >> N1 >> N2;
		cout << lcs() << endl;
	}
		
	return 0;                                                                            
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
#include <inttypes.h>

int LCS(std::string s,std::string t){
    int n,m,c[n+1][m+1];
    n=s.size();
    m=t.size();
    int maxlen=0;
    for(int i=0;i<n;i++){
        c[i][0]=0; 
    }
    for(int i=0;i<m;i++){
        c[0][i]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(s[i]==t[i]){
                c[i][j]=c[i-1][j-1]+1;
            }else{
                c[i][j]=std::max(c[i-1][j],c[i][j-1]);
            }
            maxlen=std::max(c[i][j],maxlen);
        }
    }
    return maxlen;
}
int main(){
	int N;
    
    std::cin >> N;
    std::string s1,s2;
    for(int i=0;i<N;i++){
        std::cin >> s1 >> s2;
        std::cout << LCS(s1,s2) <<std::endl;
    }
        
    
    return 0;
}