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 <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int q;
    cin >> q;
    while (q--)
    {
        string s, t;
        cin >> s >> t;
        int n = s.size();
        int m = t.size();
        vector<vector<ll>> dp(n + 10, vector<ll>(m + 10, 0));
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if (s[i - 1] == t[j - 1])
                {
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
                }
                else
                {
                    dp[i][j] = max({dp[i][j], dp[i - 1][j], dp[i][j - 1]});
                }
            }
        }
        // debug_vec2(dp);
        cout << dp[n][m] << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";}
using namespace std;
using ll = long long;

int dp[1005][1005];
vector<int> ans;

int main(void) {
    int q;
    cin >> q;
    rep (_, q) {
        string s, t;
        cin >> s >> t;

        rep (i, 1002) rep (j, 1002) dp[i][j] = 0;


        for (int si = 1; si <= s.size(); si++) {
            for (int ti = 1; ti <= t.size(); ti++) {
                if (s[si - 1] == t[ti - 1]) {
                    dp[si][ti] = dp[si - 1][ti - 1] + 1;
                }
                else {
                    dp[si][ti] = max(dp[si - 1][ti], dp[si][ti - 1]);
                }
            }
        }
        ans.push_back(dp[s.size()][t.size()]);
    }
    
    rep (i, q) cout << ans[i] << endl;
    return 0;
}

C++: #include <stdio.h>
#include <string.h>

void CSLength(char *,char *);

int c[1000][1000],a[1000];

int main() {
  int i,j=0,q;
  char s[1000],x[1000],y[1000];

  scanf("%d",&q);

  for(i=0;i<q;i++){

    scanf("%s",s);
    strcpy(&x[1],s);

    scanf("%s",s);
    strcpy(&y[1],s);

    CSLength(x,y);
    a[i]=c[strlen(x)-1][strlen(y)-1];
  }

  for(i=0;i<q;i++){
    printf("%d\n",a[i]);
  }

  return 0;
}

void CSLength(char *x,char *y){
  int m,n,i,j;

  m = strlen(x);
  n = strlen(y);

  for(i=1;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 if(c[i-1][j] >= c[i][j-1]){
	c[i][j] = c[i-1][j];
      }
      else c[i][j] = c[i][j-1];
    }
  }
}

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();

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

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 <bits/stdc++.h>
using namespace std;
int C[1001][1001];
int lc(string F, string S){
    fill(C[0],C[1000],0);
    int m = F.size(), n = S.size();
    int len=0;
    for(int i=0; i<m; i++){
        for (int j = 0; j < n; ++j) {
            if (F[i] == S[j]) {
                if (i - 1 >= 0 && j - 1 >= 0)
                    C[i][j] = C[i - 1][j - 1] + 1;
                else
                    C[i][j] = 1;
            } else if (i - 1 >= 0 && j - 1 >= 0) {
                C[i][j] = max(C[i][j - 1], C[i][j - 1]);
            }
            len = max(len, C[i][j]);
        }
    }
    return len;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string ar[n*2];
    for (int i = 0; i < n * 2; ++i) {
        cin >> ar[i];
    }
    for (int j = 0; j < n*2; j+=2) {
        cout << lc(ar[j],ar[j+1]) << endl;
    }
    return 0;
}