Go: package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	n := scanInt(sc)
	results := []int{}
	for i := 0; i < n; i++ {
		results = append(results, resolveInstance())
	}
	for _, v := range results {
		fmt.Println(v)
	}
	return
}

func resolveInstance() int {
	x, y := scanString(sc), scanString(sc)
	lx, ly := len(x), len(y)
	dp := make([][]int, lx+1)
	dp[0] = make([]int, ly+1)
	for i := 1; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
		dp[i][0] = dp[i-1][0]
		for j := 1; j <= ly; j++ {
			dp[i][j] = dp[i-1][j]
			if dp[i][j] < dp[i][j-1] {
				dp[i][j] = dp[i][j-1]
			}
			if x[i-1] == y[j-1] {
				cL := dp[i-1][j-1] + 1
				if dp[i][j] < cL {
					dp[i][j] = cL
				}
			}
		}
	}
	return dp[lx][ly]
}

const (
	remove = 0 + iota
	match
)

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<iostream>

using namespace std;

int q;

string x, y;

int dp(string x, string y){
  int longest[1051][1051];
  for(int j = 1; j <= y.size(); ++j){
    for(int i = 1; i <= x.size(); ++i){
      if(i <= 0 || j <= 0){
        longest[i][j] = 0;
      }else if(x[i - 1] == y[j - 1]){
        longest[i][j] = 1 + longest[i-1][j-1];
      }else{
        longest[i][j] = max(longest[i][j -1], longest[i - 1][j]);
      }
    }
  }
  //cout << x.size() << endl;
  return longest[x.size()][y.size()];
}

int main(){
  cin >> q;
  while(q != 0){
    q--;
    cin >> x;
    cin >> y;
    
    cout << dp(x, y) << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
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=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)<<'\n';
    }
    return 0;
}

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

typedef long long ll;
#define inf 1e9+7

int dp[1001][1001];
char x[1001],y[1001];

void init(){
    for(int i=0;i<1001;i++){
        dp[0][i]=0;
        dp[i][0]=0;
    }
}

void solve(int sn, int tn){
    for(int i=1;i<=sn;i++){
        for(int j=1;j<=tn;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]);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    string s,t;
    for(int i=0;i<n;i++){
        init();
        cin >> s >> t;
        int sn=s.size();
        int tn=t.size();
        for(int j=0;j<sn;j++){
            x[j]=s[j];
        }
        for(int j=0;j<tn;j++){
            y[j]=t[j];
        }

        solve(sn, tn);
        cout << dp[sn][tn] << endl;
    }

}

C++: #include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <map>
#define INFTY (1<<30)
#define MAX 100000000

using namespace std;

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

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

	return 0;
}

C++: //============================================================================
// Name        : LongestCommonSeq.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;

class DPMatrix{
public:
	vector<vector<int> > matrix;
	string seq1;
	string seq2;

	DPMatrix(const string sequence1, const string sequence2):matrix(),seq1(sequence1), seq2(sequence2){
		for(int i=0; i<sequence1.size()+1; i++){
			vector<int> vec(sequence2.size()+1);
			matrix.push_back(vec);
		}
	}

	void update(int i, int j){
		if(i<1 or j<1){
			cout << "caution! i: " << i << ", j: " << j << "\n";
		}

		if(seq1.at(i-1) == seq2.at(j-1)){
			matrix.at(i).at(j) = max(matrix.at(i).at(j-1), max(matrix.at(i-1).at(j), matrix.at(i-1).at(j-1)+1));
		}else{
			matrix.at(i).at(j) = max(matrix.at(i).at(j-1), max(matrix.at(i-1).at(j), matrix.at(i-1).at(j-1)));
		}
	}

	int fillMatrix(){
		for(int i=1; i<seq1.size()+1; i++){
			for(int j=1; j<seq2.size()+1; j++){
				update(i, j);
			}
		}

		return matrix.at(seq1.size()).at(seq2.size());
	}
};

int main() {
	int n;
	string sequence1, sequence2;
	cin >> n;

	for(int i=0; i<n; i++){
		cin >> sequence1;
		cin >> sequence2;

		DPMatrix dpmat(sequence1, sequence2);
		int score = dpmat.fillMatrix();

		cout << score << "\n";
	}

	return 0;
}

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

int LCS(std::string str1, std::string str2, int i, int j){
  if(str1[i] == str2[j]){
    return 1;
  }
  else{
    return 0;
  }
}

int max(int a, int b, int c){
  int m = a;
  if(b > m){
    m = b;
  }
  if(c > m){
    m = c;
  }
  return m;
}

int main(){
  int q;
  std::cin >> q;
  //int ans[q];
  std::string str1, str2;
  for(int z=0; z<q; z++){
    std::cin >> str1 >> str2;
    int l1 = str1.size();
    int l2 = str2.size();
    int DP[l1+1][l2+1];

    for(int i=0; i<=l1; i++){
      DP[i][0] = 0;
    }
    for(int j=0; j<=l2; j++){
      DP[0][j] = 0;
    }

    for(int i=1; i<=l1; i++){
      for(int j=1; j<=l2; j++){
	DP[i][j] = max(DP[i-1][j], DP[i][j-1], DP[i-1][j-1] + LCS(str1, str2, i-1, j-1));
      }
    }
    //ans[z] = DP[l1][l2];
    std::cout << DP[l1][l2] << std::endl;
  }

  /*for(int z=0; z<q; z++){
    std::cout << ans[z] << std::endl;
    }*/
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int lcs(string x, string y) {
    x = ' ' + x;
    y = ' ' + y;
    int m = x.size();
    int n = y.size();
    vector<vector<int>> c(m, vector<int>(n, 0));
    rep(i, m) {
        rep(j, n) {
            if (i == 0 || j == 0) continue;
            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]);
        }
    }
    return c[m-1][n-1];
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        string s1, s2;
        cin >> s1;
        cin >> s2;
        cout << lcs(s1, s2) << endl;
    }
}