Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	for i := 0; i < num; i++ {
		sc.Scan()
		in1 := sc.Text()
		sc.Scan()
		in2 := sc.Text()
		countMax(in1, in2)
	}
}

func countMax(in1 string, in2 string) {
	counta := make([][]int, len(in2)+1)
	for i := 0; i < len(in2)+1; i++ {
		for j := 0; j < len(in1)+1; j++ {
			counta[i] = append(counta[i], 0)
		}
	}

	// fmt.Println(counta)
	for a1, v1 := range in1 {
		i1 := a1 + 1
		for a2, v2 := range in2 {
			i2 := a2 + 1
			// fmt.Printf("1:%v 2:%v\n", i1, i2)
			if v1 == v2 {
				counta[i2][i1] = counta[i2-1][i1-1] + 1
				continue
			}
			val := counta[i2-1][i1]
			if val < counta[i2][i1-1] {
				val = counta[i2][i1-1]
			}

			counta[i2][i1] = val
		}
	}
	fmt.Println(counta[len(in2)][len(in1)])
}

C++: #include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false;}
int lcs_len(string a, string b){
	vector<vector<int>> dp(a.size()+1, vector<int>(b.size()+1, 0));
	REP(i,a.size()){
		REP(j,b.size()){
			if(a[i-1] == b[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
			}else{
				chmax(dp[i][j], dp[i-1][j]);
				chmax(dp[i][j], dp[i][j-1]);
			}
		}
	}
	return dp[a.size()][b.size()];
}

int main(){
	int Q;
	cin >> Q;
	vector<pair<string, string>> input(Q);
	rep(i,Q)cin >> input[i].first >> input[i].second;
	rep(i,Q){
		cout << lcs_len(input[i].first, input[i].second) << 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 = 1; i < n; i++) {
    c[0][j] = 0;
  }

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[i]) {
        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++: #include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;

struct edge{
  int from,to,cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef pair<int , int> P;
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
int E,V;
edge es[100001];
int kruskal(){
  sort(es,es+E,comp);
  init(V);
  int res = 0;
  for(int i=0;i<E;i++){
    edge e = es[i];
    if(!same(e.to,e.from)){
      unite(e.to,e.from);
      res += e.cost;
    }
  }
  return res;
}


int main()
{
  int co=0,dp[1001][1001];
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[1][0] = 0;
  string x,y;
  cin >> co;
  REP(i,co){
    cin >> x;
    cin >> y;
    REP(i,x.length()+1)REP(j,y.length()+1){
      if(i == 0 || j == 0)
        dp[i][j] = 0;
      else{
      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]);
      }
      }
      
    }
    cout << dp[x.length()][y.length()] << endl;
  }
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

void solve(string S, string T) {
    vector<vector<int>> dp(S.size() + 1, vector<int>(T.size() + 1, 0));
    REP(i, S.size() + 1) REP(j, T.size() + 1) {
        if (S[i - 1] == T[j - 1]) dp[i][j] = max({dp[i - 1][j - 1] + 1, dp[i - 1][j], dp[i][j - 1]});
        else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    }
    cout << dp[S.size()][T.size()] << endl;
    return;
}

int main() {
    int q;
    cin >> q;
    rep(i, q) {
        string X, Y;
        cin >> X >> Y;
        solve(X, Y);
    }
    return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INFLL=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void solve_(){
     string a,b;
    cin >> a >> b;
    
    static int dp[1000][1000];
    fill_n((int*)dp,1000*1000,0);
    
    rep(i,0,a.size()){
        rep(j,0,b.size()){
            if(i!=0) dp[i][j]=dp[i-1][j];
            if(j!=0) dp[i][j]=max(dp[i][j],dp[i][j-1]);
            
            if(a[i]!=b[j]) continue;
            
            if(i==0||j==0) dp[i][j]=1;
            else dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
        }
    }
    
    cout << dp[a.size()-1][b.size()-1] << endl;
}

void solve(){
    int n;
    cin >> n;
    rep(i,0,n) solve_();
}

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

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>

using namespace std;

int main()
{
    int N;
    int data[1001][1001]={};
    cin>>N;
    string str1,str2;
    for(int i=0;i<N;i++){
        cin>>str1>>str2;
        for(int i=0;i<str1.length();i++){
            for(int j=0;j<str2.length();j++){
                if(str1[i]==str2[j]){
                    data[i+1][j+1]=data[i][j]+1;
                }else{
                    data[i+1][j+1]=data[i+1][j]>data[i][j+1]?data[i+1][j]:data[i][j+1];
                }
            }
        }
        cout<<data[str1.length()][str2.length()]<<endl;
    }
}