Go: package main

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

func main() {
	for q := ReadInt(); q > 0; q-- {
		x, y := ReadString(), ReadString()
		fmt.Println(LCS(x, y))
	}
}

func LCS(x, y string) int {
	dp := make([][]int, len(x)+1)
	for i := 0; i < len(x)+1; i++ {
		dp[i] = make([]int, len(y)+1)
	}
	for i := 0; i < len(x); i++ {
		for j := 0; j < len(y); j++ {
			dp[i+1][j+1] = Max(dp[i+1][j], dp[i][j+1])
			if x[i] == y[j] {
				dp[i+1][j+1] = Max(dp[i+1][j+1], dp[i][j]+1)
			}
		}
	}
	return dp[len(x)][len(y)]
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

C++: #include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define INFTY 2000000001
#define MAX 1001

char str[150][2][MAX];
int n = 0;
int c[MAX][MAX];

void lcs(int i) {
  int len0 = strlen(str[i][0]);
  int len1 = strlen(str[i][1]);
  for (int j = 0; j < len0; j++) c[j][0] = 0;
  for (int j = 0; j < len1; j++) c[0][j] = 0;
  for (int m = 0; m < len0; m++) {
    for (int n = 0; n < len1; n++) {
      if (str[i][0][m] == str[i][1][n]) {
        c[m+1][n+1] = c[m][n] + 1;
      } else if (c[m+1][n] >= c[m][n+1]) {
        c[m+1][n+1] = c[m+1][n];
      } else {
        c[m+1][n+1] = c[m][n+1];
      }
    }
  }
}

int main() {
  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) {
    scanf("%s", str[i][0]);
    scanf("%s", str[i][1]);
  }

  for (int i = 0; i < n; i++) {
    lcs(i);
    printf("%d\n", c[strlen(str[i][0])][strlen(str[i][1])]);
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int q; cin>>q;
	for(int i=0;i<q;++i){
		string x,y; cin>>x>>y;
		vector<vector<int>>dp(y.size()+1,vector<int>(x.size()+1));
		for(auto&j:dp)j.at(0)=0; for(auto&j:dp.at(0))j=0;
		for(int j=0;j<y.size();++j){
			for(int k=0;k<x.size();++k){
				if(y.at(j)==x.at(k))dp.at(j+1).at(k+1)=dp.at(j).at(k)+1;
				else dp.at(j+1).at(k+1)=max({dp.at(j).at(k),dp.at(j).at(k+1),dp.at(j+1).at(k)});
			}
		}
		cout<<dp.back().back()<<"\n"s;
	}
}

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

#define MAX 150
#define MAXL 1000

int C[MAXL+1][MAXL+1];

int lec(string X,string Y)
{
    int XL = X.length();
    int YL = Y.length();
    for(int i=0;i<=XL;i++)
        C[i][0] = 0;
    for(int i=0;i<=YL;i++)
        C[0][i] = 0;
    for(int i=0;i<=XL;i++)
    {
        for(int j=0;j<=YL;j++)
        {
            if(X[i+1]==Y[j+1])
            {
                C[i+1][j+1] = C[i][j]+1;
            }
            else if(C[i][j+1] > C [i+1][j])
            {
                C[i+1][j+1] = C[i-1][j+1];
            }else{
                C[i+1][j+1] = C[i+1][j];
            }
        }
    }
    return C[XL][YL];
}

int main()
{
    int q;
    string x,y;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>x>>y;
        cout<<lec(x,y)<<endl;
    }
    return 0;
}

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

using namespace std;

static const int N = 1000;
static int c[N + 1][N + 1] = {};

static int lcs(string& X, string& Y) {
  const size_t m(X.size());
  const size_t n(Y.size());

  int lcs = 0;
  
  for (size_t i = 1; i <= m; i++) {
    for (size_t j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      }
      else {
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      lcs = max(lcs, c[i][j]);
    }
  }
  return lcs;
}

int main() {
  int n;
  cin >> n;

  string X, Y;
  for (int i = 0; i < n; i++) {
    cin >> X;
    cin >> Y;
    cout << lcs(X, Y) << endl;
  }
 
  return 0;
}