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 <bits/stdc++.h>
#define INF 100000

using namespace std;
typedef long long int ll;

int dh[4] = {1,0,-1,0};
int dw[4] = {0,1,0,-1};

int main()
{
    int q;
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        string X,Y;
        cin >> X >> Y;
        int lx = X.length();
        int ly = Y.length();
        vector<vector<int>>dp(lx+1,vector<int>(ly+1,0));
        for(int i = 1; i <= lx; i++)
        {
            for(int j = 1; j <= ly; 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]);
            }
        }
        cout << dp[lx][ly] << endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
#include <string>

#include <vector>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

int nxtx[] = {1, 0};
int nxty[] = {0, 1};

int main(int argc, char const *argv[]) {
    int q;
    cin >> q;
    string X, Y;
    typedef pair<int, int> pint;
    for (int k = 0; k < q; k ++) {
        cin >> X;
        cin >> Y;
        int lenX = X.size();
        int lenY = Y.size();
        int dp[lenX + 1][lenY + 1];
        for (int i = 0; i <= lenX; i ++) {
            dp[i][0] = 0;
        }
        for (int i = 0; i <= lenY; i ++) {
            dp[0][i] = 0;
        }

        for (int i = 1; i <= lenX; i ++) {
            for (int j = 1; j <= lenY; 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]);
                }
            }
        }
        cout << dp[lenX][lenY] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int q;
  scanf("%d",&q);
  std::vector<std::string > X(q);
  std::vector<std::string > Y(q);
  for (int i=0; i<q; i++){
    std::cin >> X[i];
    std::cin >> Y[i];
  }
  int val[1002][1002];
  for (int k=0; k<q; k++){
    for (int i=0; i<X[k].length(); i++){
      for (int j=0; j<Y[k].length(); j++){
        if (X[k][i]==Y[k][j]){
          if (i==0 && j==0){
            val[i][j]=1;
          }
          if (i>0 && j>0){
            val[i][j]=val[i-1][j-1]+1;
          } else {
            val[i][j]=1;
          }
        } else if (i==0 && j==0){
          val[i][j]=0;
        } else if (i==0){
          val[i][j]=val[i][j-1];
        } else if (j==0){
          val[i][j]=val[i-1][j];
        } else {
          val[i][j]=std::max(val[i-1][j], val[i][j-1]);
        }
      }
    }
    int length = val[X[k].length()-1][Y[k].length()-1];
    printf("%d\n", length);
  }
  return 0;
}

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

using namespace std;

int solve(string s1, string s2){
    int L[s1.size()+1][s2.size()+1];
    for(int i=0;i<s1.size();i++){
        for(int j=0;j<s2.size();j++){
            if(i==0 || j==0){
                L[i][j]=0;
            }
            else if(s1[i] == s2[j]){
                L[i][j] = 1 + L[i-1][j-1];
            }
            else{
                L[i][j] = max(L[i][j-1],L[i-1][j]);
            }
        }
    }
    return L[s1.size()][s2.size()];
}

int main(){
    int n ; cin >> n;
    for(int i=0;i<n;i++){
        string s1,s2; cin>> s1 >> s2;\
        cout << solve(s1,s2) << endl;
    }
}

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

#define MAX 1000
int dp[MAX+1][MAX+1];

int lcs(string X, string Y){
    int m = X.size();
    int n = Y.size();
    for(int i = 0; i <= m; i++) dp[i][0] = 0;
    for(int j = 0; j <= n; j++) dp[0][j] = 0;

    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(X[i-1] == Y[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }else{
                dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }

    return dp[m][n];
}

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

    string X, Y;

    for(int i = 0; i < q; i++){
        cin >> X >> Y;
        cout << lcs(X,Y) << endl;
    }

    return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int q;
  cin >> q;
  rep(i,q){
    string X,Y; cin >> X >> Y;
    vector<vector<int>> dp(1010,vector<int>(1010,0));
    rep(i,X.size())rep(j,Y.size()){
      if(X[i]==Y[j]){
        dp[i+1][j+1]=max({dp[i][j]+1,dp[i+1][j],dp[i][j+1]});
      }
      else{
        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
    cout << dp[X.size()][Y.size()] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#define lth 1000

using namespace std;

int main()
{
	int n, L[100][100], Lmax = 0, *save;
	string Xi[lth], Yi[lth];
	cin >> n;
	save = new int[n];
	for (int k = 0; k < n; k++)
	{
		string X, Y;
		cin >> X >> Y;
		for (int i = 0; i <= X.length(); i++)
		{
			if (i != 0)
				Xi[i] = X.substr(0, i );
		}
		for (int i = 0; i <= Y.length(); i++)
		{
			if (i != 0)
				Yi[i] = Y.substr(0, i );
		}
		for (int i = 0; i <= X.length(); i++)
			for (int j = 0; j <= Y.length(); j++)
			{
				if (i == 0 || j == 0)
					L[i][j] = 0;
				else if (Xi[i][i - 1] == Yi[j][j - 1])
				{
					L[i][j] = L[i - 1][j - 1] + 1;
				}
				else
				{
					L[i][j] = (L[i][j - 1] > L[i - 1][j]?L[i][j - 1] : L[i - 1][j]);
				}
				if (Lmax < L[i][j]) Lmax = L[i][j];
			}
		save[k] = Lmax;
	}
	for (int i = 0; i < n; i++)
		cout << save[i] << endl;
}