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++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007

signed main()
{
	init();
	solve();
}

int q, xl, yl;
string x, y;

void init()
{
	cin >> q;
}

int dp[1010][1010];

void reset()
{
	rep(i, xl+2) rep(j, yl+2) dp[i][j] = 0;
}


void solve()
{
	rep(cnt, q) {
		cin >> x >> y;
		xl = x.length();
		yl = y.length();
		reps(i, 1, xl+1) reps(j, 1, yl+1) {
			if (x[i-1] == y[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
			else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
		}
		cout << dp[xl][yl] << endl;
		reset();
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
constexpr auto INF = 2147483647;
typedef long long ll;

int main(){

  int q;
  cin >> q;
  string x, y;
  int len_x, len_y;
  rep(i,q){
    cin >> x >> y;
    len_x = x.size()+1; len_y = y.size()+1;
    vector<vector<int>> lscDP(len_x, vector<int>(len_y));
    rep(i,len_x)rep(j,len_y){
      if(i==0 || j == 0) lscDP[i][j] = 0;
      else if(x[i-1] == y[j-1]) lscDP[i][j] = max(lscDP[i-1][j-1] +1, max(lscDP[i-1][j], lscDP[i][j-1]));
      else lscDP[i][j] = max(lscDP[i-1][j], lscDP[i][j-1]);
    }

    cout << lscDP[len_x-1][len_y-1] << endl;
  }


  return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

int sets;
string sentences[500];
int dp[500][1001][1001];

int main(){
    cin >> sets;
    for(int i = 0; i < sets*2; i++){
        cin >> sentences[i];
    }

    for(int i = 0; i < sets*2; i+=2){
        for(int n = 0; n < sentences[i].size(); n++){
            for(int m = 0; m < sentences[i+1].size(); m++){
                if(sentences[i][n] == sentences[i+1][m]){
                    dp[i][n+1][m+1]= dp[i][n][m] + 1;
                }else{
                    dp[i][n+1][m+1] = max(dp[i][n+1][m],dp[i][n][m+1]);
                }
            }
        }
    }

    for(int i = 0; i<sets*2; i+=2){
        cout << dp[i][sentences[i].size()][sentences[i+1].size()] << endl;
    }
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>
 
#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define if_range(x, w, h) if (w <= x && x <= h)
#define BitCheck(a,b)   (a >> b) & 1
#define BitSet(a,b)       a |= (1 << b)
#define BitunSet(a,b)    a &= ~(1 << b)
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
 
int compare_int(const void* a, const void* b) { return *(int*) a - *(int*) b; }
 
int main() {
    int n, m, a, dp[1002][1002] = { 0 };
    char s[1001], t[1001];
    scanf("%d", &a);
    for (int k = 0; a > k; k++) {
        scanf("%s %s", s, t);
        n = strlen(s);
        m = strlen(t);
        for (int i = 1; n >= i; i++) {
            for (int j = 1; m >= j; j++) {
                if (s[i - 1] == t[j - 1])dp[i][j] = dp[i - 1][j - 1] + 1;
                else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
        printf("%d\n", dp[n][m]);
    }
    return 0;
}

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

using namespace std;

int lcs(string a, string b) {
  int longest_length = 0;
  int m = a.size(), n = b.size();
  int table[m+1][n+1];
  for(int i = 0; i < m+1; i++) table[i][0] = 0; 
  for(int i = 0; i < n+1; i++) table[0][i] = 0; 
  for(int i = 1; i < m+1; i++) {
    for(int j = 1; j < n+1; j++) {
      if(a[i] == b[j]){
        table[i][j] = table[i-1][j-1] + 1;
      } else {
        table[i][j] = max(table[i-1][j], table[i][j-1]);
      } 
      longest_length = max(longest_length, table[i][j]);
    }
  }
  return longest_length;
}

int main() {
  int n = 0;
  cin >> n;
  string a, b;
  for(int i = 0; i < n; i++) {
    cin >> a >> b;
    int l = lcs(a, b);
    cout << l << endl;
  }
}