Go: package main

import "fmt"

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

	for q := 0; q < n; q++ {
		var s1, s2 string
		fmt.Scan(&s1, &s2)
		s1, s2 = " " + s1, " " + s2

		dp := make([][]int, len(s1))
		for i := range dp {
			dp[i] = make([]int, len(s2))
		}

		max := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					dp[i][j] = dp[i-1][j-1] + 1
				} else {
					dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
				}
				max = Max(max, dp[i][j])
			}
		}

		fmt.Println(max)
	}
}

func Max(n ...int) int {
	max := n[0]
	for _, v := range n[1:] {
		if v > max {
			max = v
		}
	}
	return max
}

C++: #include<stdio.h>
??
int LCS(char x[], char y[]) {
????int xn = 0, yn = 0, flag = 0, i, j, max = 0;
????int c[1001][1001];
??????
????while (flag == 0)
????{
????????if (x[xn] != '\0')
????????{
????????????xn++;
????????}
????????else
????????{
????????????flag = 1;
????????}
????}
??????
????flag = 0;
??????
????while (flag == 0)
????{
????????if (y[yn] != '\0')
????????{
????????????yn++;
????????}
????????else
????????{
????????????flag = 1;
????????}
????}
????for (i = 1; i < xn + 1; i++) c[i][0] = 0;
????for (j = 1; j < yn + 1; j++) c[0][j] = 0;
??????
????for (i = 1; i < xn + 1; i++)
????{
????????for (j = 1; j < yn + 1; j++)
????????{
????????????if (x[i - 1] == y[j - 1])
????????????{
????????????????c[i][j] = c[i - 1][j - 1] + 1;
????????????}
????????????else if (c[i - 1][j] >= c[i][j - 1])
????????????{
????????????????c[i][j] = c[i - 1][j];
????????????}
????????????else
????????????{
????????????????c[i][j] = c[i][j - 1];
????????????}
????????????if (max < c[i][j]) max = c[i][j];
????????}
????}
??????
????return max;
}
??
int main(void) {
????char x[1000], y[1000];
????int q, i;
??????
????scanf("%d", &q);
??????
????for (i = 0; i < q; i++)
????{
????????scanf("%s", x);
????????scanf("%s", y);
????????printf("%d\n", LCS(x, y));
????}
??????
????return 0;
}

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

static const int N = 1000;

int lcs(string X, string Y) {
  int c[N+1][N+1];
  int m = X.size();
  int n = Y.size();
  int maxl = 0;

  X = ' '+X;
  Y = ' '+Y;

  for(int i = 0; i <= m; i++) c[i][0] = 0;
  for(int j = 1; j <= n; j++) c[0][j] = 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]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

signed main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }
  return 0;
}

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

string a, b;
int q;
// iまで、jまででの答え
int dp[1005][1005] = {0};

int solve();

int main() {
  cin >> q;
  for(int qq = 0; qq < q; ++qq) {
    cin >> a >> b;
    cout << solve() << endl;
    for(int i = 1; i <= a.size(); ++i)
      for(int j = 1; j <= b.size(); ++j) dp[i][j] = 0;
  }
  return 0;
}

int solve() {
  for(int i = 1; i <= a.size(); ++i)
    for(int j = 1; j <= b.size(); ++j) {
      dp[i][j] =
          max(dp[i][j - 1],
              max(dp[i - 1][j - 1] + (a[i - 1] == b[j - 1]),
                  dp[i - 1][j]));
    }
  return dp[a.size()][b.size()];
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
using namespace std;
typedef long long ll;
//定義場所//
int i, j, k, l, m, n;
int N, Q;
vector <int> Ans;
////////////

int main()
{
	int N;
	cin >> N;
	for (k = 0; k < N; k++) {
		vector<vector<int> >dp(1001, vector<int>(1001, 0));
		int ans = 0;
		string s1, s2;
		cin >> s1 >> s2;
		s1 = ' ' + s1;
		s2 = ' ' + s2;
		for (i = 0; i < s1.size(); i++) { dp[i][0] = 0; }
		for (i = 1; i < s2.size(); i++) { dp[0][i] = 0; }
		for (i = 1; i < s1.size(); i++) {
			for (j = 1; j < s2.size(); j++) {
				if (s1[i] == s2[j]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				}
				else {
					dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
				}
				ans = max(ans, dp[i][j]);
			}
		}
		Ans.push_back(ans);
	}
	for (i = 0; i < Ans.size(); i++) {
		cout << Ans[i] << endl;
	}
}

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

int lcs(string X, string Y) {
  int cs[1001][1001];
  int m = X.size();
  int n = Y.size();
  int answer = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 1; i <= m; i++) cs[i][0] = 0;
  for (int j = 1; j <= n; j++) cs[0][j] = 0;

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

  return answer;
}

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

  int n;
  cin >> n;

  string X, Y;

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

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
//#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

void solve() {
    string s, t; cin >> s >> t;
    int n = s.length(), m = t.length();
    auto dp = vec<int>(n + 1, m + 1);
    FOR(i, 0, n)FOR(j, 0, m) {
        chmax(dp[i + 1][j + 1], dp[i][j + 1]);
        chmax(dp[i + 1][j + 1], dp[i + 1][j]);
        if (s[i] == t[j])chmax(dp[i + 1][j + 1], dp[i][j] + 1);
    }
    cout << dp[n][m] << "\n";
}

int main() {
    init();

    int q; cin >> q;
    FOR(i, 0, q)solve();
}