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 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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(e,array) for(const auto& e : array)
#define lower_index(v,a) (int)distance(v.begin(), lower_bound((v).begin(),(v).end(),a))
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
typedef long long ll;
const int inf = 1<<28;
const ll INF = 1LL<<57;
const ll MOD = 1e9+7;

int main(){ 
    ll N; cin >> N;
    rep(_,N){
        string x,y;cin >> x >> y;
        ll X = x.size();
        ll Y = y.size();
        vector<vector<ll>> dp(X+1,vector<ll>(Y+1,0));
        rep(i,X)rep(j,Y){
            if (x[i]==y[j]) chmax(dp[i+1][j+1],dp[i][j]+1);
            else chmax(dp[i+1][j+1],max(dp[i+1][j],dp[i][j+1]));
        }
        cout << dp[X][Y] << endl;
    }

}

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

struct node{
  int value;
  node *next;
  node(int value, node *next):value(value),next(next){};
};
#define INF ( 1 << 28 )
string lcs(string &a, string &b){
  map< int , vector< int > > M;
  for(int i = b.size() - 1 ; i >= 0 ; i--){
    M[b[i]].push_back(i);
  }
  vector<int > HM(a.size() + 1, INF);
  HM[0] = -INF;
  vector<node*> link(a.size() + 1);
  for(int i = 0 ; i < a.size() ; i++ ){
    if(M.count(a[i])){
      vector< int > NEWHM = M[a[i]];
      for(int j = 0 ; j < NEWHM.size() ; j++ ){
        int k = distance( HM.begin(), lower_bound( HM.begin(), HM.end(), NEWHM[j]));
        HM[k] = NEWHM[j];
        link[k] = new node( b[NEWHM[j]], link[k - 1]);
      }
    }
  }
  string ans;
  for(node* p = link[distance(HM.begin(),lower_bound(HM.begin(),HM.end(),INF-1))-1];p;p = p->next){
    ans += (char)p -> value;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
int main(){
  int q;
  cin >> q;
  while(q--){
    string a, b;
    cin >> a >> b;
    string ans = lcs( a, b);
    cout << ans.size() << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int lcs(string x, string y) {
    static int c[1001][1001];
    int m = x.size();
    int n = y.size();
    int max1 = 0;
    x = ' ' + x;
    y = ' ' + y;
    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]);
            max1 = max(max1, c[i][j]);
 
        }
    }
    return max1;
}
 
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 <stdio.h>
#include <string.h>
#define N 1000

void Ics(char *X, char *Y)
{
   int c[N][N];
   int m, n, i, j;

   m = strlen(X);
   n = strlen(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 - 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 ];
         }
      }
   }
   printf("%d\n", c[ m ][ n ]);
}
     
int main()
{
   int n, i;
   char X[N], Y[N];

   scanf("%d", &n);
   for ( i = 0; i < n; i++ ) {
      scanf("%s%s", X, Y);
      Ics(X, Y);
   }
   return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 1010;

int main(int argc, char const *argv[]) {
  int q;
  cin >> q;
  for (auto k = 0; k < q; k++) {
    vector<vector<int>> dp(MAXN, vector<int>(MAXN, 0));
    string s1, s2;
    cin >> s1 >> s2;
    auto n = s1.size();
    auto m = s2.size();
    for (size_t i = 0; i < n; i++) {
      for (size_t j = 0; j < m; j++) {
        if (s1[i] == s2[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
        } else {
          dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        }
      }
    }
    cout << dp[n][m] << 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;
	X = " " + X;
	Y = " " + Y;
	for(int i = 0; i <= m; i++) c[i][0] = 0;
	for(int j = 0; 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++: #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
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 = 0; i < m; i++) c[i][0] = 0;
	for (int j = 0; 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][j - 1], c[i - 1][j]);
			}
		}
	}
	maxl = c[m][n];
	return maxl;
}

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