Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 1001

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func lcs(x, y string) int {
	var c [N][N]int
	m := len(x)
	n := len(y)
	var maxl int

	x = " " + x
	y = " " + y

	for i := 1; i <= m; i++ {
		for 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
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	var out bytes.Buffer
	for i := 0; i < q; i++ {
		sc.Scan()
		s1 := sc.Text()
		sc.Scan()
		s2 := sc.Text()
		out.WriteString(fmt.Sprintf("%d\n", lcs(s1, s2)))
	}
	return strings.TrimRight(out.String(), "\n")
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int q,i,j,k,l1,l2,m,n;
    string X,Y;
    cin>>q;
    for(i=0; i<q; i++)
    {
        cin>>X>>Y;
        l1=X.length()+1;
        l2=Y.length()+1;
        int arr[l2][l1];
        for(k=0; k<l1; k++)
        {
            arr[0][k]=0;
        }
        for(k=0; k<l2; k++)
        {
            arr[k][0]=0;
        }
        for(k=1; k<l2; k++)
        {
            for(j=1; j<l1; j++)
            {
                if(Y[k-1]==X[j-1])
                {
                    arr[k][j]=1+arr[k-1][j-1];
                }
                else
                {
                    m=arr[k-1][j];
                    n=arr[k][j-1];
                    arr[k][j]=max(m,n);
                }
            }
        }
        cout<<arr[l2-1][l1-1]<<endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int q;
string x, y;
int n, m;
int dp[1001][1001];
int main()
{
	cin >> q;
	for(int i=0; i<q; i++)
	{
		for(int j=0; j<1001; j++)
		{
			for(int k=0; k<1001; k++)
			{
				dp[j][k]=0;
			}
		}
		cin >> x >> y;
		n=x.size();
		m=y.size();
		for(int j=1; j<=n; j++)
		{
			for(int k=1; k<=m; k++)
			{
				if(x[j-1]==y[k-1])
				{
					dp[j][k]=dp[j-1][k-1]+1;
				}
				else
				{
					dp[j][k]=max(dp[j-1][k], dp[j][k-1]);
				}
			}
		}
		cout << dp[n][m] << endl;
	}
	return 0;
}

C++: from string import ascii_letters

def llcs(x, y):
    pm = dict((zip(ascii_letters, [0] * 52)))
    for c in pm:
        for i, xc in enumerate(x):
            if c == xc:
                pm[c] |= (1 << i)
    
    V = (1 << len(x)) - 1
    
    for yc in y:
        V = ((V + (V & pm[yc])) | (V & ~pm[yc]))
    
    ans = bin(V)[-len(x):].count('0')
    
    return ans

from sys import stdin

def solve():
    file_input = stdin
    q = int(file_input.readline())
    for i in range(q):
        s1 = file_input.readline().rstrip()
        s2 = file_input.readline().rstrip()
        print(llcs(s1, s2))

solve()

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

signed main() {
  int n;
  cin >> n;
  for (int c = 0; c < n; c++) {
    string x, y;
    cin >> x >> y;

    int dp[x.size() + 1][y.size() + 1];
    for (int i = 0; i < x.size() + 1; i++) {
      dp[i][0] = 0;
    }

    for (int j = 0; j < y.size() + 1; j++) {
      dp[0][j] = 0;
    }
      
    for (int i = 1; i < x.size() + 1; i++) {
      for (int j = 1; j < y.size() + 1; j++) {
	if (x[i - 1] == y[j - 1]) {
	  dp[i][j] = dp[i - 1][j - 1] + 1;
	} else {
	  dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
	}
      }
    }

    cout << dp[x.size()][y.size()] << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;int l(string a,string b){int m=a.size(),n=b.size(),i=0,j,s=0,c[1001][1001]={};for(a=' '+a,b=' '+b;++i<=m;)for(j=0;++j<=n;s=s<c[i][j]?c[i][j]:s)c[i][j]=a[i]==b[j]?c[i-1][j-1]+1:c[i-1][j]>c[i][j-1]?c[i-1][j]:c[i][j-1];return s;}main(){string a,b;int n;for(cin>>n;n--;cin>>a>>b,cout<<l(a,b)<<endl);}

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

using namespace std;

int N=1000;

int LCS(string x,string y){
	int c[N+1][N+1],LCSlen=0;
	int m=x.size();
	int n=y.size();
	x=' '+x;
	y=' '+y;
	for(int i=1;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]=c[i-1][j]>c[i][j-1] ? c[i-1][j]:c[i][j-1];
			LCSlen=LCSlen>c[i][j] ? LCSlen:c[i][j];
		}
	}
	return LCSlen;
}

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

C++: import java.util.*;

public class alds1_10 {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String X = null, Y = null;
        int[][] dp = new int[1001][1001];

        int q = sc.nextInt();

        for (int i = 0; i < q; ++i) {
            X = sc.next();
            Y = sc.next();
            for (int x = 0; x < X.length(); ++x) {
                for (int y = 0; y < Y.length(); ++y) {
                    if (X.charAt(x) == Y.charAt(y)) {
                        dp[x + 1][y + 1] = dp[x][y] + 1;
                    }
                    else {
                        if (dp[x + 1][y] > dp[x][y + 1]) {
                            dp[x + 1][y + 1] = dp[x + 1][y];
                        }
                        else {
                            dp[x + 1][y + 1] = dp[x][y + 1];
                        }
                    }
                }
            }
            System.out.printf("%d\n", dp[X.length()][Y.length()]);
        }
    }
}

C++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

main {
  int n;
  cin >> n;
  while (n--) {
    string x, y;
    cin >> x >> y;
    vvi dp(x.size() + 1, vi(y.size() + 1));
    dp[0][0] = 0;
    loop(i, 1, x.size() + 1) loop(j, 1, y.size() + 1) {
      if (x[i - 1] == y[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
        continue;
      }
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    }
    cout << dp.back().back() << endl;
  }
}