Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>

using namespace std;

const char *X, *Y;
int X_length, Y_length;

int table_lcs[1001][1001];

int lcs(int x_begin, int y_begin) {
	int i, j, to;
	int max = 0;
	int v_lcs;
	bool alreadySeenTable[256];
	if (table_lcs[x_begin][y_begin] != -1) {
		return table_lcs[x_begin][y_begin];
	}
	
	for (i = 0; i < 256; i++) {
		alreadySeenTable[i] = false;
	}
	i = x_begin;
	to = Y_length-1;
	while(i <= X_length-1) {
		j = y_begin;
		if (alreadySeenTable[X[i]] == true) {
			i++;
			continue;
		}
		bool found = false;
		while (j <= to) {
			if (X[i] == Y[j]) {
				v_lcs = lcs(i + 1, j + 1) + 1;
				if (v_lcs > max) {
					max = v_lcs;
				}
				found = true;
				break;
			}
			else {
				j++;
			}
		}
		if (found == false) {
			alreadySeenTable[X[i]] = true;
			i++;
		}
		else {
			alreadySeenTable[X[i]] = true;
			i++;
			to = j - 1;
		}
	}
	return table_lcs[x_begin][y_begin] = max;
}

int main() {

	int N;
	cin >> N;
	string stringX, stringY;

	for (int i = 1; i <= N; i++) {
		for (int i = 0; i < 1001; i++) {
			for (int j = 0; j < 1001; j++) {
				table_lcs[i][j] = -1;
			}
		}
		cin >> stringX >> stringY;
		X = stringX.c_str();
		X_length = stringX.size();
		Y = stringY.c_str();
		Y_length = stringY.size();
		printf("%d\n", lcs(0, 0));
	}
	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int dp[11111][11111];

void print(string s, string t) {
   int n = s.size(), m = t.size();
   rep (i, n+1) {
      rep (j, m+1) {
         printf("%2lld ", dp[i][j]);
      }
      puts("");
   }
}

int dist(string s, string t) {
   fill(dp[0], dp[1010], 1 << 28);
   dp[0][0] = 0;
   dp[0][0] = 0;
   int N = s.size(), M = t.size();
   rep (i, N+1) dp[i][0] = i;
   rep (i, M+1) dp[0][i] = i;

   rep (i, N) {
      rep (j, M) {
         dp[i+1][j+1] = min({dp[i][j+1]+2, dp[i+1][j]+2, dp[i][j] + (s[i] != t[j])});
      }
   }

   cout << dp[N][M] << endl;
}

int lcs(string s, string t) {
   for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < t.size(); j++) {
         dp[i+1][j+1] = (s[i] == t[j] ? dp[i][j]+1 : max(dp[i][j+1], dp[i+1][j]));
      }
   }
   return dp[s.size()][t.size()];
}

signed main() {
   int n;
   cin >> n;

   while (n--) {
      string s, t;
      cin >> s >> t;

      cout << lcs(s, t) << endl;
   }

   return 0;
}

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

int lcs (string x, string y) {
	int m = x.length();
	int n = y.length();
	int maxl = 0;
	vector<vector<int>> c(m + 1, vector<int>(n + 1, 0));

	x = ' ' + x;
	y = ' ' + y;
	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() {
	int q; cin >> q;
	for(int cnt = 0; cnt < q; cnt++){
		string x, y;
		cin >> x >> y;
		cout << lcs(x, y) << endl;
	}
	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;
    int i,j;

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

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

    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;

}

int main()
{
    string s1,s2;
    int n;

    cin >> n;

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

    return 0;

}

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

constexpr int N=1000;

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

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

   return 0;
}

C++: #include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define INFTY 2000000001
#define MAX 1001

char str[150][2][MAX];
int n = 0;
int c[MAX][MAX];

void lcs(int i) {
  int len0 = strlen(str[i][0]);
  int len1 = strlen(str[i][1]);
  for (int j = 0; j < len0; j++) c[j][0] = 0;
  for (int j = 0; j < len1; j++) c[0][j] = 0;
  for (int m = 0; m < len0; m++) {
    for (int n = 0; n < len1; n++) {
      if (str[i][0][m] == str[i][1][n]) {
        c[m+1][n+1] = c[m][n] + 1;
      } else if (c[m+1][n] >= c[m][n+1]) {
        c[m+1][n+1] = c[m+1][n];
      } else {
        c[m+1][n+1] = c[m][n+1];
      }
    }
  }
}

int main() {
  scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) {
    scanf("%s", str[i][0]);
    scanf("%s", str[i][1]);
  }

  for (int i = 0; i < n; i++) {
    lcs(i);
    printf("%d\n", c[strlen(str[i][0])][strlen(str[i][1])]);
  }

  return 0;
}