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 <iostream>
#include <cstring>
#include <string>

using namespace std;


using ll = long long;


ll c[1001][1001];
void solve()
{
    string X, Y;
    cin >> X >> Y;

    memset(c, 0, sizeof(c));
    for (ll i = 0; i <= X.length(); i++)
        c[i][0] = 0;
    for (ll i = 0; i <= Y.length(); i++)
        c[0][i] = 0;

    for (ll i = 1; i <= X.length(); i++) {
        for (ll j = 1; j <= Y.length(); j++) {
            if (X[i - 1] == Y[j - 1]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }
        }
    }

    cout << c[X.length()][Y.length()] << endl;
}


int main()
{
    ll q;
    ll c[151][151];

    cin >> q;
    for (ll i = 0; i < q; i++) {
        solve();
    }
}

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

const int length = 1005;
int dp[length][length];

void LCS(std::string X, std::string Y)
{
  auto m = X.length();
  auto n = Y.length();


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

  for (int i=1; i<=m; ++i)
    {
      for (int j=1; j<=n; ++j)
        {
          if (X[i-1] == Y[j-1])
            dp[i][j] = dp[i-1][j-1] + 1;
          else
            {
              dp[i][j] = std::max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
}

int main ()
{
  int q;
  std::cin >> q;

  std::string X, Y;
  for (int i=0; i<q; ++i)
    {
      std::cin >> X >> Y;
      LCS(X, Y);
      std::cout << dp[X.length()][Y.length()] << std::endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int NN;
string s1, s2;
int dp[1001][1001];

int run(){
	int N1 = s1.length();
	int N2 = s2.length();
	
	rep(i1, N1+1)
	rep(i2, N2+1){
		if(i1 == 0 || i2 == 0) dp[i1][i2] = 0;
		else{
			if(s1[i1-1] == s2[i2-1]) dp[i1][i2] = dp[i1-1][i2-1] + 1;
			else dp[i1][i2] = max(dp[i1-1][i2], dp[i1][i2-2]);
		}
	}
	return dp[N1][N2];
}

int main() {
	cin >> NN;
	rep(i, NN){
		cin >> s1;
		cin >> s2;
		cout << run() << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;


int lcs(string x, string y){
    int m = x.size();
    int n = y.size();
    int c[m+1][n+1];
    x = ' ' + x;
    y = ' ' + y;
    int maxv = 0;
    rep(i, m+1) 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(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]);
            maxv = max(maxv, c[i][j]);
        }
    }
    return c[m][n];
}

int main(){
    int n, ans;
    cin >> n;
    rep(i, n){
        string x, y;
        cin >> x >> y;
        ans = lcs(x, y);
        cout << ans << endl;
    }
}