Go: package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

C++: /*
??????-???_
  -????????????=- ???
  ''???-???"''-=?????????=- ???_
          "'rfi??????-???"''-?????????=-???_
           .i?????????i=??? "''???-???"''-?????????=-???_
           i?????????i.??????=- .   "'???-???"''-?????????-???_
          .i???=???i"'???-"_-=?????????=- .  "'???-???"''-?????????-???_
          i?????????i.         " ???"_-=?????????=-.,.??¨rfi??????-???"???|
         .i?????????i                  "  ???"  -???i??????i "'???-''???
         i??????=i                             "i??????i
        .i?????????i                             i??????i
        i?????????i                              i??????i
       .i?????????i                               i??????i
       i?????????i                               i??????i
      .i?????????i                               i???=i
     i????????????i                                 i??????i
     i????????????i                                 i??????i
     i????????????i                                i??????i
     i????????????i                                 i??????i
    i????????????i                                  i??????i
    i????????????i                                  i=??????i
   i????????????i                                  i?????????i
   i???????????????i                                  ?¨"""?¨
   ???????????????                         
*/

#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { -1, 0,  1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<LL, LL>;
using vi = vector<int>;
using vd = vector<double>;
using vvi = vector<vi>;
using vll = vector<LL>;

//==============================================
vvi dp(1050, vi(1050));

int lcs(string x, string y) {
	int ans = 0;
	int m = x.length();
	int n = y.length();

	x = ' ' + x;
	y = ' ' + y;

	REP3(i, 1, m) {
		REP3(j, 1, n) {
			if (x[i] == y[j]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else if (dp[i - 1][j] >= dp[i][j - 1]) {
				dp[i][j] = dp[i - 1][j];
			} else {
				dp[i][j] = dp[i][j - 1];
			}

			ans = max(ans, dp[i][j]);
		}
	}

	return ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int q;
	cin >> q;

	string str1, str2;
	REP(i, q) {
		cin >> str1 >> str2;
		cout << lcs(str1, str2) << "\n";
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int q;
  cin >> q;
  rep(repert, q) {
    string X, Y;
    cin >> X >> Y;
    vector<vector<int>> dp(X.size()+1, vector<int>(Y.size()+1));
    rep(i, X.size()) {
      rep(j, Y.size()) {
        if(X[i] == Y[j]) {
          dp[i+1][j+1] = dp[i][j]+1;
        } else {
          dp[i+1][j+1] = max({dp[i+1][j], dp[i][j+1]});
        }
      }
    }
    cout << dp[X.size()][Y.size()] << endl;
  }
  return 0;
}

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

int DP[1010][1010];

int main() {
  int n;
  cin >> n;
  for (auto t=0; t<n; t++) {
    string A, B;
    cin >> A >> B;
    int LA = (int) A.size();
    int LB = (int) B.size();
    fill(&DP[0][0], &DP[0][0]+1010*1010, 0);
    for (auto i=-1; i<LA; i++) {
      for (auto j=-1; j<LB; j++) {
        if (i == -1 || j == -1) {
          DP[i+1][j+1] = 0;
        } else if (A[i] == B[j]) {
          DP[i+1][j+1] = 1 + DP[i][j];
        } else {
          DP[i+1][j+1] = max(DP[i+1][j], DP[i][j+1]);
        }
      }
    }
    cout << DP[LA][LB] << endl;
  }
}