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 <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int linersearch(int a[], int n, int x);
void insetrtionsort(int a[], int n);
void printarray(int n, int a[]);
void babblesort(int n, int a[]);
void selectionsort(int n, int a[]);
void countingsort(int n, int a[]);
void minimumcostsort(int n, int a[]);

int linersearch(int a[], int n, int x)
{
    int ret = 0;
    for (int i = 1; i < n; i++)
    {
        if (a[i] == x)
        {
            ret = 1;
            break;
        }
    }
    return ret;
}

void insetrtionsort(int a[], int n)
{
    int j, v;
    for (int i = 1; i < n; i++)
    {
        v = a[i];
        j = i - 1;
        while (j >= 0 && a[j] > v)
        {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for (int i = 0; i < n; i++)
        {
            cout << a[i] << " ";
        }
        cout << endl;
    }
}

void babblesort(int n, int a[])
{
    int flag = 1;
    int counter = 0;
    int tmp;
    while (flag)
    {
        flag = 0;
        for (int j = n - 1; j > 0; j--)
        {
            if (a[j] < a[j - 1])
            {
                swap(a[j], a[j - 1]);
                counter++;
                flag = 1;
            }
        }
    }
    printarray(n, a);
    cout << counter << endl;
}

void selectionsort(int n, int a[])
{
    int minj;
    int counter = 0;
    for (int i = 0; i < n; i++)
    {
        minj = i;
        for (int j = i; j < n; j++)
        {
            if (a[j] < a[minj])
                minj = j;
        }
        if (i != minj)
        {
            swap(a[minj], a[i]);
            counter++;
        }
    }
    printarray(n, a);
    cout << counter << endl;
}

void countingsort(int n, int a[])
{
    int b[n] = {};
    int k = 0;
    for (int i = 0; i < n; i++)
        k = max(a[i], k);
    int c[k + 1] = {};
    for (int i = 0; i < n; i++)
        c[a[i]]++;
    for (int i = 1; i < k + 1; i++)
        c[i] += c[i - 1];
    for (int i = n - 1; i > -1; i--)
    {

        b[c[a[i]] - 1] = a[i];
        c[a[i]]--;
    }
    printarray(n, b);
}

void minimumcostsort(int n, int a[])
{
    int maxa, maxindex, cost;
    cost = 0;
    for (int i = n - 1; i > 0; i--)
    {
        maxa = a[0];
        maxindex = 0;
        for (int j = 1; j <= i; j++)
        {
            if (a[j] > maxa)
            {
                maxa = a[j];
                maxindex = j;
            }
        }
        if (maxindex != i)
        {
            cost += maxa + a[i];
            swap(a[maxindex], a[i]);
        }
    }
    cout << cost << endl;
}

void printarray(int n, int a[])
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;
}

int gcd(int a, int b)
{
    if (a < b)
    {
        int t = a;
        a = b;
        b = t;
    }
    cout << a << " " << b << endl;
    if (b == 0)
        return a;
    else
        return gcd(b, b % a);
}

ll fib(int x){
    if (x == 0 || x == 1)
        return 1;
    else;
        return fib(x - 1) + fib(x - 2);
}

int lcs(string s, string t)
{
    int la = s.size();
    int lb = t.size();
    int lcs[la + 1][lb + 1] = {};
    for (int i = 0; i < la; i++)
    {
        for (int j = 0; j < lb; j++)
        {
            if (s[i] == t[j])
            {
                lcs[i + 1][j + 1] = lcs[i][j] + 1;
            }
            else
            {
                lcs[i + 1][j + 1] = max(lcs[i][j + 1], lcs[i + 1][j]);
            }
        }
    }

    return lcs[la][lb];
}

int main()
{
    int q, m, ans;
    string s, t;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> s >> t;
        cout << lcs(s, t) <<endl;
    }
    return 0;
}

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

class TLcsSolver
{
    typedef std::vector<std::vector<int> > TTable;
    TTable FTable;
    std::string FArray1;
    std::string FArray2;

    int Count(int i, int j)
    {
        if(i == 0 || j == 0) return 0;
        if(FArray1[i-1] == FArray2[j-1]){
            return FTable[i-1][j-1] + 1;
        }
        return std::max(FTable[i-1][j], FTable[i][j-1]);
    }
    void Solve()
    {
        for(std::size_t i = 1; i < FTable.size(); ++i){
            for(std::size_t j = 1; j < FTable[i].size(); ++j){
                FTable[i][j] = Count(i, j);
            }
        }
    }
public:
    TLcsSolver(const std::string& a, const std::string& b)
     : FArray1(a), FArray2(b)
     , FTable(a.size()+1, std::vector<int>(b.size()+1, 0))
    {
        Solve();
        // Print();
    }
    int Answer()const
    {
        return FTable[FArray1.size()][FArray2.size()];
    }
    void Print()const
    {
        for(std::size_t i = 0; i < FTable.size(); ++i){
            for(std::size_t j = 0; j < FTable[i].size(); ++j){
                std::cout << FTable[i][j] << '\t';
            }
            std::cout << '\n';
        }
    } 
};

int main()
{
    int n;
    std::cin >> n;
    char a[1000];
    char b[1000];
    for(int i = 0; i < n; ++i){
        std::gets(a);
        std::gets(b);
        std::printf("%d", TLcsSolver(a, b).Answer());
    }
    return 0;
}