Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
#include <inttypes.h>

int LCS(std::string s, std::string t){
    int n, m, c[1001][1001] = {0};
    n = s.size();
    m = t.size();
    int maxlen = 0;
    for(int i = 1; i <= n; i++){
        c[i][0] = 0;
    }
    for(int i = 1; i <= m; i++){
        c[0][i] = 0;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i - 1] == t[j - 1]){
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else{
                c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
            }
            maxlen = std::max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}
int main(){
    int N;

    std::cin >> N;
    std::string s1, s2;
    for(int i = 0; i<N; i++){
        std::cin >> s1 >> s2;
        std::cout << LCS(s1, s2) << std::endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long double ld;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*
Xのi番目とYのj番目までのLCS
*/

int lcs[1010][1010];

void solve(){

    int q;
    cin >> q;
    vector<int> v;
    rep(i,q){
        string s,t;
        cin >> s;
        cin >> t;
        rep(i,1010){
            rep(j,1010){
                lcs[i][j]=0;
            }
        }
        for(int i=0; i<s.length(); i++){
            for(int j=0; j<t.length(); j++){
                if(s[i]==t[j]) lcs[i+1][j+1]=lcs[i][j]+1;
                else lcs[i+1][j+1]=max(lcs[i+1][j], lcs[i][j+1]);
            }
        }
        v.emplace_back(lcs[s.length()][t.length()]);
    }

    for(auto e: v){
        cout << e << endl;
    }
}

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

C++: #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;

int main() {
  int t;
  cin >> t;
  vi results;
  for (int dataset = 0 ; dataset < t ; dataset++) {
    string a, b;
    cin >> a;
    cin >> b;
    vvi len(a.length()+1, vi(b.length()+1, 0));
    for (int ia = 0 ; ia < a.length() ; ia++) {
      for (int ib = 0 ; ib < b.length() ; ib++) {
        if (a[ia] == b[ib]) {
          len[ia+1][ib+1] = len[ia][ib]+1;
        } else {
          len[ia+1][ib+1] = max(len[ia+1][ib], len[ia][ib+1]);
        }
      }
    }
    results.pb(len[a.length()][b.length()]);
  }

  for (int it = 0 ; it < t ; it++) {
    printf("%d\n", results[it]);
  }

  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const int INF = 1e9;
const int MOD = 17;
const vector<int> dy = {-1,0,1,0};
const vector<int> dx = {0,1,0,-1};

void solve() {
    string S,T; cin >> S >> T;
    int N = S.size(),M = T.size();
    vector<vector<int>> dp(N + 1,vector<int>(M + 1,0));
    rep(i,N)rep(j,M) {
        if (S[i] == T[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]);
    }
    printf("%d\n",dp[N][M]);
}

int main() {
    int Q; cin >> Q;
    rep(i,Q) solve();
}

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], maxl = 0, i, j;
  int m = x.size();
  int n = y.size();

  x = ' ' + x;
  y = ' ' + y;
 
  for(i = 1; i <= m; i++) c[i][0] = 0;
  for(i = 1; i <= n; i++) c[0][i] = 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 x, y;
  int q, i;

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

C++: #include <utility>
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>


using namespace std;

int Q;


int main(){
  cin >> Q;
  string X,Y;
  int L[1010][1010]={0};
  int len = 0;
  for(int q=0;q<Q;++q){
    cin >> X;
    cin >> Y;
    len = X.length();
      for(int j=1;j<len+1;++j){//kkkkkkkkkkkkkkkkkkkkkkk
	for(int i=1;i<len+1;++i){
	  if(i <= 0 || j <= 0) L[i][j] = 0;
	  else if(X[i] == Y[j]) L[i][j] = 1 + L[i-1][j-1];
	  else L[i][j] = max(L[i][j-1],L[i-1][j]);
	}
      }

    cout << L[len][len] << endl;
  }
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)

#define N 1000

int lcs(string X, string Y) {
  int m = X.size();
  int n = Y.size();
  int c[m + 1][n + 1];
  int maxlen = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  c[0][0] = 0;
  FOR(i, 1, m + 1) c[i][0] = 0;
  FOR(j, 1, n + 1) c[0][j] = 0;

  FOR(i, 1, m + 1) {
    FOR(j, 1, n + 1) {
      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]);
      }
      maxlen = max(maxlen, c[i][j]);
    }
  }

  return maxlen;
}

int main(void) {
  string X, Y;
  int n; cin >> n;
  REP(i, n) {
    cin >> X >> Y;
    cout << lcs(X, Y) << endl;
  }
  return 0;
}

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