Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>

#define SIZE 1002
int FTable[SIZE][SIZE];
class TLcsSolver
{
    const char* FArray1;
    const char* FArray2;
    const int Fn1;
    const int Fn2;

    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 < Fn1; ++i){
            for(std::size_t j = 1; j < Fn2; ++j){
                FTable[i][j] = Count(i, j);
            }
        }
    }
    void Print()const
    {
        for(std::size_t i = 0; i < Fn1; ++i){
            for(std::size_t j = 0; j < Fn2; ++j){
                printf("%d\t", FTable[i][j]);
            }
            printf("\n");
        }
    } 
public:
    TLcsSolver(const char* a, const char* b)
     : FArray1(a), FArray2(b)
     , Fn1(std::strlen(a)), Fn2(std::strlen(b))
    {
        Solve();
        // Print();
    }
    int Answer()const
    {
        return FTable[Fn1-1][Fn2-1];
    }
};

int main()
{
    int n;
    std::scanf("%d\n", &n);
    char a[SIZE];
    char b[SIZE];
    for(int i = 0; i < n; ++i){
        std::fgets(a, SIZE, stdin);
        std::fgets(b, SIZE, stdin);
        std::printf("%d\n", TLcsSolver(a, b).Answer());
    }
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
 
#define MAX 1010
#define max(a,b) ((a<b)?b:a)
 
char s[MAX], t[MAX];
int dp[MAX][MAX],path[MAX][MAX];
 
int LCS() {
  int n = strlen(s);
  int m = strlen(t);
  memset(dp,0,sizeof dp);
  int i,j,maxi=0;
  for(i=0;i<n;i++) {
    for(j=0;j<m;j++) {
      if( i ) dp[i][j] = max(dp[i][j],dp[i-1][j]);
      if( j ) dp[i][j] = max(dp[i][j],dp[i][j-1]);
      if( s[i] == t[j] ) {
    dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1);
    maxi = max(maxi,dp[i+1][j+1]);
      }
    }
  }
  return maxi;
}
 
int main() {
  int n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++) {
  scanf(" %s",&s[0]);
  scanf(" %s",&t[0]);
  printf("%d\n",LCS());
  }
  return 0;
}

C++: n=int(input())
ans=[]
for k in range(n):
    s1=input()
    s2=input()
    dp=[[0 for i in range(len(s2)+1)] for j in range(len(s1)+1)]
    for i in range(1,len(s1)+1):
        for j in range(1,len(s2)+1):
            if s1[i-1]==s2[j-1]:
                dp[i][j]=dp[i-1][j-1]+1
            else:
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])


    ans.append(dp[len(s1)][len(s2)])
for a in ans:
    print(a)

C++: #ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <numeric>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mod = 1000000007;

typedef long long num;

#define bs(n) (1ll<<(ll)(n))
#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define rrep(i, n) for(ll (i) = 1;(i) <= (n);(i)++)

int v[1010][1010], f[1010][1010][2];

int lcs2(string &a, string &b) {
    memset(v, 0, sizeof(int[1010][1010]));
    memset(f, 0, sizeof(int[1010][1010][2]));
    int n = a.length(), m = b.length(), ri = 0, rj = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i] == b[j] && v[i + 1][j + 1] < v[i][j] + 1) {
                v[i + 1][j + 1] = v[i][j] + 1;
                f[i + 1][j + 1][0] = i;
                f[i + 1][j + 1][1] = j;
            }
            if (v[i + 1][j] < v[i][j]) {
                v[i + 1][j] = v[i][j];
                f[i + 1][j][0] = i;
                f[i + 1][j][1] = j;
            }
            if (v[i][j + 1] < v[i][j]) {
                v[i][j + 1] = v[i][j];
                f[i][j + 1][0] = i;
                f[i][j + 1][1] = j;
            }
        }
    }
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= m; j++)
            if (v[ri][rj] < v[i][j]) {
                ri = i;
                rj = j;
            }
    string ret;
    int rn = v[ri][rj];
    while (ri != 0 && rj != 0) {
        if (f[ri][rj][0] == ri - 1 && f[ri][rj][1] == rj - 1) {
            ret.push_back(a[ri]);
        }
        int rii = f[ri][rj][0];
        int rjj = f[ri][rj][1];
        ri = rii;
        rj = rjj;
    }
    return rn;
}


int main() {
    int q;
    cin >> q;
    string a, b;
    rep(i, q) {
        cin >> a >> b;
        cout << lcs2(a, b) << endl;
    }
}