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++: #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 = 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] = 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++: //Longest Common Subsequence
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int q;
  string X, Y;
  int dp[1001][1001]={};
  int m, n;
  int ans;


  cin >> q;
  REP(s, q){
    dp[1001][1001]={};
    cin >> X >> Y;
    m=X.size();
    n=Y.size();
    REP(i, m){
      REP(j, n){
        if(X[i] == Y[j]) dp[i+1][j+1] = dp[i][j]+1;
        else dp[i+1][j+1]=max(dp[i][j+1], dp[i+1][j]);
      }
    }
    cout << dp[m][n] <<endl;
  }


  return 0;
}

C++: #include<iostream>
using namespace std;
int lcs(string a,string b)
{
    if(a.length()<=0||b.length()<=0)
    {
        return 0;
    }
    else if(a[a.length()-1]==b[b.length()-1])
    {
        return 1+lcs(a.substr(0,a.length()-1),b.substr(0,b.length()-1));
    }
    else
    {
        return max(lcs(a.substr(0,a.length()),b.substr(0,b.length()-1)),lcs(a.substr(0,a.length()-1),b.substr(0,b.length())));
    }
};
int main()
{
    int num;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        string a,b;
        cin>>a>>b;
        cout<<lcs(a,b)<<endl;
    }
}

C++: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    *t++;
    while(t != V.end()) {
        cout << " " << *t++;
        // if(t != V.end()) cout << " ";
    }
    cout << endl;
};
vector<vector<int>> dp(1001, vector<int>(1001));

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q;
    string S, T;
    cin >> Q;
    rep(q, Q) {
        cin >> S >> T;
        dp.assign(S.size() + 1, vector<int>(T.size() + 1, 0));
        rep(i, 0, S.size()) {
            rep(j, 0, T.size()) {
                if(S.at(i) == T.at(j)) {
                    dp.at(i + 1).at(j + 1) = dp.at(i).at(j) + 1;
                } else {
                    dp.at(i + 1).at(j + 1) =
                        max(dp.at(i + 1).at(j), dp.at(i).at(j + 1));
                }
            }
        }
        cout << dp.at(S.size()).at(T.size()) << endl;
    }
}

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

static const int N = 1000;

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


int main(){
    ios::sync_with_stdio(false);
    string s1, s2;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
      cin >> s1 >> s2;
      cout << lcs(s1, s2) << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
int dp[1000+1][1000+1];
int lim;
//int cost_vec[/*num*/];
//int val_vec[/*num*/];
int main() {
	int num;
	cin >> num;
	vector<string> vec(2*num);
	REP(i, num) {
		cin >> vec[2 * i];
		cin >> vec[2 * i + 1];
	}
	REP(i, num) {
		memset(dp, 0, sizeof(dp));
		REP(k, vec[i * 2].size()) {
			REP(n, vec[i * 2+1].size()) {
				if (vec[i * 2][k] == vec[i * 2 + 1][n]) {
					dp[k + 1][n + 1] = dp[k][n] + 1;
				}
				else {
					dp[k + 1][n + 1] = max(dp[k][n + 1], dp[k + 1][n]);
				}
			}
		}
		cout << dp[vec[i * 2].size()][vec[i * 2+1].size()] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h> 

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int q; cin >> q;
    REP(i, q)
    {
        string a, b; cin >> a >> b;
        vvi dp(a.length()+1, vi(b.length()+1));
        REP(j, a.length())
        {
            REP(k, b.length())
            {
                if(a[j] == b[k]) dp[j+1][k+1] = dp[j][k]+1;
                chmax(dp[j+1][k+1], dp[j][k+1]);
                chmax(dp[j+1][k+1], dp[j+1][k]);
            }
        }
        cout << dp[a.length()][b.length()] << endl;
    }
}

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

int table[150][150];
int l1, l2;

int checkLCS(string s1, string s2){
	table[150][150] = {};
	

	for (int i = 1; i <= l1 - 1;i++) {
		for (int j = 1; j <= l2 - 1;j++) {
			table[i][j] = max(max(table[i-1][j],table[i][j-1]), (s1[i]==s2[j])+table[i-1][j-1]);
		}
	}


	return table[l1-1][l2-1] + 1;
	
}



int main(void) {
	
	int q;
	string s1, s2;

	cin >> q;

	for (int i = 0;i <= q - 1;i++) {
		cin >> s1 >> s2;
		l1 = s1.length();
		l2 = s2.length();

		cout << checkLCS(s1, s2) << endl;
	}

	return 0;
}