Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    int q;
    cin >> q;
    while(q--){
        string x,y;
        cin >> x >> y;
        vector<vector<int>> dp(x.size()+1,vector<int>(y.size()+1,0));
        rep(i,x.size())rep(j,y.size()){
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
            if(x[i]==y[j]) dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + 1);
        }
        cout << dp.back().back() << endl;
    }
    return 0;
}

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

using namespace std;

int main(){
  string X,Y;
  cin>>X>>Y;

  int N[X.size()+1][Y.size()+1];

  for(int i=0;i<=X.size();i++){
    for(int j=0;j<=Y.size();j++){

      N[i][j]=1;
}
  }

  /*
  for(int i=0;i<X.size();i++){
    cout<<X[i]<<endl;
  }

for(int i=0;i<Y.size();i++){
    cout<<Y[i];
  }
  */

  
for(int i=0;i<=X.size();i++){
  N[i][0]=0;
  }

for(int i=0;i<=Y.size();i++){
  N[0][i]=0;
  }

 int point;

  for(int i=1;i<=X.size();i++){
    for(int j=1;j<=Y.size();j++){
      if(X[i-1]==Y[j-1]){
	point=1;
	
      }else{
	point=0;
      }
       N[i][j]=max({N[i-1][j],N[i][j-1],N[i-1][j-1]+point});
       point=0;
}
   
  }


  //answer
  for(int i=0;i<=X.size();i++){
    for(int j=0;j<=Y.size();j++){

      cout<<N[i][j]<<" ";
      if(j==Y.size()){
	cout<<endl;
      }
}
  }


}

C++: #include <bits/stdc++.h>
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; // X[0] に空文字を挿入
  Y = ' ' + Y;
  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 - 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;
  }
}

C++: #include <iostream>
#include <string>
const int MAX_X = 1100;
const int MAX_Y = 1100;


int main() {
  std::string X;
  std::string Y;
  int q;
  int answers[160];
  std::cin >> q;
  int dp[MAX_X][MAX_Y];
  
  for(int p=0; p<q; ++p) {
    std::cin >> X;
    std::cin >> Y;

    for(int i=0; i<MAX_X; ++i) {
      for(int j=0; j<MAX_Y; ++j) {
        dp[i][j] = 0;
      }
    }

    int xlen = X.size();
    int ylen = Y.size();

    X = " " + X;
    Y = " " + Y;

    for(int i=1; i<=xlen; ++i) {
      for(int j=1; j<=ylen; ++j) {
        if(X[i] == Y[j]) {
          dp[i][j] = dp[i-1][j-1] + 1;
        } else {
          dp[i][j] = std::max(
            dp[i][j-1],
            dp[i-1][j]
          );
        }
      }
    }
    answers[p] = dp[xlen][ylen];  
  }

  for(int i=0; i<q; ++i) {
    std::cout << answers[i] << std::endl;
  }

}

C++: #include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
  
using namespace std;

#define pi 3.141592653589793

int solve(string s1, string s2, int l1, int l2)
{
	int a[1001][1001];
	for(int i = 0; i <= l1; i++){
		a[i][0] = 0;
	}
	for(int i = 0; i <= l2; i++){
		a[0][i] = 0;
	}
	for(int i = 1; i <= l1; i++){
		for(int j = 1; j <= l2; j++){
			if(s1[i - 1] == s2[j - 1]) a[i][j] = a[i - 1][j - 1] + 1;
			else a[i][j] = max(a[i - 1][j], a[i][j - 1]);
		}
	}
	return a[l1][l2];
}

int main()
{
	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		string s1, s2;
		cin >> s1 >> s2;
		cout << solve(s1, s2, s1.length(), s2.length()) << endl;
	}
	return 0;
}

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


int main() {
	int n, m, q;
	string a, b;//two sequences
	int M[1010][1010] = { { 0 } };//Memory matrix

	cin >> q;
	for (int l = 0; l < q; l++)
	{
		cin >> a >> b;
		n = a.length();
		m = b.length();
		for (int i = 0; i <= n; i++)
		{
			for (int j = 0; j <= m; j++)
			{
				if (a[i] == b[j])
				{
					M[i + 1][j + 1] = M[i][j] + 1;
				}
				else
				{
					M[i + 1][j + 1] = max(M[i][j + 1], M[i + 1][j]);
				}
			}
		}

		cout << M[n][m] << endl;//The time complexity equals to O (n * m)
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int MAX_L = 10000;
int q;

string data[MAX_N][2];
ll mem[MAX_L][MAX_L];

ll eval(string s1, string s2, int i, int j){
	int ii = i - 1;
	int jj = j - 1;
	if (ii == -1 || jj == -1) return 0;
	if (s1[ii] == s2[jj]) return mem[i - 1][j - 1] + 1;
	if (s1[ii] != s2[jj]) return max(mem[i - 1][j], mem[i][j - 1]);
	throw "exception";
}

ll solve(string s1, string s2){

	int L1 = s1.size();
	int L2 = s2.size();
	rep(i, L1 + 1){
		rep(j, L2 + 1)
		{
			mem[i][j] = eval(s1, s2, i, j);
		}
	}

	return mem[L1][L2];
}

int main() {

	cin >> q;
	rep(i, q){
		cin >> data[i][0];
		cin >> data[i][1];
	}

	rep(i, q){
		cout << solve(data[i][0], data[i][1]) << endl;
	}
}