Go: package main

import "fmt"

func initialize_grid(width int,height int)[][]int{
	var grid [][]int
	for i:=0;i<height+1;i++{
		var grid_row  []int
		for j:=0;j<width+1;j++{
			grid_row = append(grid_row,0)
		}
		grid = append(grid,grid_row[:])
	}
	return grid
}

func ma(x int,y int)int{
	if x >= y{
		return x
	}else{
		return y
	}
}

func main()  {
	//Take input
	var num int
	var st1,st2 string
	var string_pairs [][]string
	fmt.Scan(&num)
	for i:=0;i<num;i++{
		var string_pair []string
		fmt.Scan(&st1)
		fmt.Scan(&st2)
		string_pair = append(string_pair,st1,st2)
		string_pairs = append(string_pairs,string_pair)
	}
	//DP
	//initialize grid
	for i:=0;i<num;i++{
		string_1 := string_pairs[i][0]
		string_2 := string_pairs[i][1]

		dp := initialize_grid(len(string_2),len(string_1))

		for j:=1;j<len(string_1)+1;j++{
			for k:=1;k<len(string_2)+1;k++{
				if string_1[j-1] == string_2[k-1]{
					dp[j][k] = dp[j-1][k-1] + 1
				}else{
					dp[j][k] = ma(dp[j-1][k],dp[j][k-1])
				}
			}
		}
		fmt.Println(dp[len(string_1)][len(string_2)])
	}
}

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



auto lcs(const std::string& a, const std::string& b, std::vector<std::vector<int> >*tp) {
	auto tab = *tp;

	for (auto&e : tab) {
		std::fill(std::begin(e),std::end(e),0);
	}

	for (decltype(a.size()) ai{1}; ai <= a.size();++ai) {
		for (decltype(ai) bi{1}; bi<=b.size(); ++bi) {
			if (a[ai-1] == b[bi-1])
				tab[ai][bi] = tab[ai - 1][bi - 1] + 1;
			else
				tab[ai][bi] = std::max(tab[ai - 1][bi], tab[ai][bi - 1]);
		}
	}
	return tab[a.size()][b.size()];
}

int main() {
	int q;
	std::cin >> q;

	std::vector<std::vector<int>> buf{};
	buf.resize(1005);
	for (auto&e : buf)
		e.resize(1005);

	for (int i{}; i < q; ++i) {
		std::string x, y;
		std::cin >> x >> y;
		std::cout << lcs(x, y, &buf)<<"\n";
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define FOR(index, init, max) for (int index = (init); index < (max); i++)
#define REP(index, max) for (int index = 0; index < (max); i++)
#define FOREACH(x, array) for (auto&& (x) : array)
#define VECCIN(vec) for (auto&& vec_i : vec) cin >> vec_i
#define VECCOUT(vec) for (const auto& vec_i : vec) cout << vec_i << endl

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

    int dp[1001][1001] = {0};

    while(q > 0) {
        string x, y;
        cin >> x >> y;

        for (int x_i = 0; x_i < x.length(); x_i++) {
            for (int y_i = 0; y_i < y.length(); y_i++) {
                if (x[x_i] == y[y_i]) {
                    dp[x_i + 1][y_i + 1] = dp[x_i][y_i] + 1;
                }
                else {
                    dp[x_i + 1][y_i + 1] = max(dp[x_i][y_i + 1], dp[x_i + 1][y_i]);
                }
            }
        }

        cout << dp[x.length()][y.length()] << endl;
        q--;
    }

    return 0;
}

C++: 
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#define MAX 1001

using namespace std;

int LCS(char *X, char *Y)
{
    int m = strlen(X);
    int n = strlen(Y);
    int  c[MAX][MAX] = {0};
    for (int i = 0; i <= m; i++)
    {
        c[0][i] = 0;
    }
    for (int j = 0; j <= n; j++)
    {
        c[j][0] = 0;
    }

    for (int i = 1; i <= m; i++)
    {
        for (int 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];
                }
            }
        }
    }

    return c[m][n];
}

int main(int argc, char *argv[])
{
    char X[MAX], Y[MAX];
    int q;
    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%s", X);
        scanf("%s", Y);
        printf("%d\n", LCS(X, Y));
    }
    return 0;
}

C++: #include <iostream> 
#include <cstring> 
using namespace std;
int c[1001][1001];

int lcs(string x, string y)
{
    int maxl = 0;
    int m = x.length(), n = y.length();
 
    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 = max(maxl, c[i][j]);
        } 
    } 
    return maxl;
}

int main()
{
    string x,y;
    int q;
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        int ans = lcs(x, y);
        cout<<ans<<endl;
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int CalcLCS(string X, string Y){
  int c[1001][1001];
  int m = SZ(X);
  int n = SZ(Y);
  REP1(i,m) c[i][0]=0;
  REP1(j,n) c[0][j]=0;

  REP0(i,m){
    REP0(j,n){
      if (X[i]==Y[j]) {
        c[i+1][j+1] = c[i][j] + 1;
      } else {
        c[i+1][j+1] = max(c[i][j+1], c[i+1][j]);
      }
    }
  }
  return c[m][n];
}


int main(int argc, char const *argv[]) {
  int q; std::cin >> q;
  string X,Y;

  REP0(i,q){
    std::cin >> X >> Y;
    std::cout << CalcLCS(X,Y) << '\n';
  }

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define _A_ true
using namespace std;
 
int main(){
  int n,AC=0,strA,strB;
  int dp[1010][1010];
  char *A = new char[1500];
  char *B = new char[1500];
 
  scanf("%d",&n);
  while(_A_){
    if(AC == n)break;
    scanf("%s",A);
    scanf("%s",B);
    for(int i=0;i<1010;i++)for(int j=0;j<1010;j++)dp[i][j]=0;
strA = strlen(A); 
strB = strlen(B);

    for(int i=0;i<strA;i++){
      for(int j=0;j<strB;j++){
    if(A[i] == B[j]){
      dp[i+1][j+1]=dp[i][j]+1;
    }
    else{
      if(dp[i+1][j] > dp[i][j+1]){
        dp[i+1][j+1]=dp[i+1][j];
      }
      else {
        dp[i+1][j+1] = dp[i][j+1];
      }
    }
      }
    }
    printf("%d\n",dp[strA][strB]);
    AC++;
  }
  delete [] A;
  delete [] B;
 
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
    using namespace std;
int lcs(string x,string y){
    int c[1010][1010];
    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(){
    int q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}