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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

class LCS_Solver
{
    vector<VL> vl;
    string &s1;
    string &s2;

public:
    LCS_Solver(size_t s, string &s1, string &s2)
        : vl(s, VL(s, -1)), s1(s1), s2(s2)
    {
        vl[0][0] = 0;
        REP(i, s)
        {
            vl[0][i] = 0;
            vl[i][0] = 0;
        }
    }

    LL solve_memoize(int s1n, int s2m);
    LL solve_dp(int s1n, int s2m) const;
};

LL LCS_Solver::solve_memoize(int s1n, int s2m)
{
    // cout << s1n << ", " << s2m << endl;
    if (vl[s1n][s2m] >= 0)
    {
        return vl[s1n][s2m];
    }
    else
    {
        LL ans;
        if (s1[s1n - 1] == s2[s2m - 1])
        {
            ans =
                solve_memoize(s1n - 1, s2m - 1) + 1;
            vl[s1n][s2m] = ans;
            return ans;
        }
        else
        {
            ans = max(
                solve_memoize(s1n - 1, s2m),
                solve_memoize(s1n, s2m - 1));
            vl[s1n][s2m] = ans;
            return ans;
        }
    }
}

const size_t MAX_SIZE = 2000;

int main()
{
    int n;
    cin >> n;

    LL ans;
    REP(_, n)
    {
        string s1, s2;
        cin >> s1;
        cin >> s2;
        // cout << s1.size() << " " << s2.size() << endl;

        ans = LCS_Solver(MAX_SIZE, s1, s2)
                  .solve_memoize(s1.size(), s2.size());
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

int c[1005][1005];

int lcs(string s1, string s2){
    int n = s1.size();
    int m = s2.size();
    s1 = " " + s1;
    s2 = " " + s2;
    for(int i = 0; i <= n; i++) c[i][0] = 0;
    for(int i = 0; i <= n; i++) c[0][i] = 0;

    int ans = 0;
    for (int i1 = 1; i1 <= n; i1++){
        for(int i2 = 1; i2 <= m; i2++){
            if(s1[i1] == s2[i2]){
                c[i1][i2] = c[i1-1][i2-1] + 1;
            }else{
                c[i1][i2] = max(c[i1-1][i2], c[i1][i2-1]);
            }
        }
        ans = max(ans, c[i1][m]);
    }
    return ans;
}

int main(){
    int q;
    cin >> q;
    vector<int> ans(q);
    for(int i = 0; i < q; i++){
        string s1, s2;
        cin >> s1 >> s2;
        ans[i] = lcs(s1, s2);
    }
    rep(i,q) cout << ans[i] << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int T;
    cin >> T;
    while(T--){
        string a, b;
        cin >> a >> b;
        int M = sz(a), N = sz(b);
        int dp[M+1][N+1];
        rep(i, M+1) dp[i][0] = 0;
        rep(j, N+1) dp[0][j] = 0;
        rep(i, M){
            rep(j, N){
                if(a[i] == b[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[M][N] << endl;
    }
}

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;
}
  
  for(i = 0; i < q; i++){
    cin >> x >> y;
    cout << lcs(x, y) << endl;
  }
  return 0;
}