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

using namespace std;

const int N = 1000;

int c[N + 1][N + 1];

int LCS(string X, string Y) {
  int m = X.size();
  int n = Y.size();
  int maxl = 0;
  X = ' ' + X;  // X[0]に空白を挿入
  Y = ' ' + Y;  // Y[0]に空白を挿入

  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;
}

int main() {
  string s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    cout << LCS(s1, s2) << "\n";
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

void solve() {
    string x, y;
    cin >> x >> y;
    ll lx = len(x), ly = len(y);
    vector<vector<ll>> dp(lx + 1, vector<ll>(ly + 1, 0));
    rep(i, lx) {
        rep(j, ly) {
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            if (x[i] == y[j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
        }
    }
    cout << dp[lx][ly] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll t;
    cin >> t;
    rep(i, t) solve();
    return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

int lcs(string X,string Y){
	int m = X.size();
	int n = Y.size();
	int maxi = 0; 
	int C[1001][1001];
	X = ' ' + X;
	Y = ' ' + Y;
	for(int i = 1;i <= m;i++) 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]);
			}
			maxi = max(maxi,C[i][j]);
		}
	}
	return maxi;
}

int main(){
	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;

#define MAX_STR_LEN 1001

int mat[MAX_STR_LEN][MAX_STR_LEN];

int lcs(string x, string y)
{
    int xlen = x.length();
    int ylen = y.length();
    for (int i = 1; i <= xlen; i++)
    {
        for (int j = 1; j <= ylen; j++)
        {
            if (i != 0 && j != 0)
            {
                mat[i][j] = (x[i - 1] == y[j - 1]) ? mat[i - 1][j - 1] + 1 : max(mat[i - 1][j], mat[i][j - 1]);
            }
            else
            {
                mat[i][j] = 0;
            }
        }
    }

    return mat[xlen][ylen];
}

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        string x, y;
        cin >> x >> y;
        printf("%d\n", lcs(x, y));
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int value;
  node *next;
  node(int value,node *next):value(value),next(next){}
};
int INF=1LL<<55LL;
string lcs(string x,string y){
  int n=x.size(),m=y.size();
  map<char,vector<int> > M;
  for(int j=m-1;j>=0;j--) M[y[j]].push_back(j);
  vector<int> xs(n+1,INF);
  xs[0]=-INF;
  vector<node* > link(n+1);
  for(int i=0;i<n;i++){
    if(M.count(x[i])){
      vector<int> ys=M[x[i]];
      for(int j=0;j<(int)ys.size();j++){
	int k=distance(xs.begin(),lower_bound(xs.begin(),xs.end(),ys[j]));
	xs[k]=ys[j];
	link[k]=new node(y[ys[j]],link[k-1]);
      }
    }
  }
  string res;
  int l=distance(xs.begin(),lower_bound(xs.begin(),xs.end(),INF-1))-1;
  for(node *p=link[l];p!=NULL;p=p->next)
    res.push_back(p->value);
  return res;
}
signed main(){
  int q;
  cin>>q;
  while(q--){
    string x,y;
    cin>>x>>y;
    cout<<lcs(x,y).size()<<endl;
  }
  return 0;
}

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



int lcs(string x, string y){

  int m = x.length();
  int n = y.length();

  int c[m + 1][n + 1];

  for(int i = 0; i <= m; i++){
    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 - 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];
      }
      cout << "c" << i << j << c[i][j] << endl;
    }

  }

  return c[m][n];
}

int main(){

  int q;

  string x, y;

  cin >> q;

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



  return 0;
}