Go: package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)
var q int
var X, Y string

func lcs(X, Y string) int {
	lenX := len(X)
	lenY := len(Y)
	dp := make([][]int, lenX+1)
	for i := 0; i < lenX+1; i++ {
		dp[i] = make([]int, lenY+1)
	}

	res := 0
	for i := 1; i < lenX+1; i++ {
		for j := 1; j < lenY+1; j++ {
			if X[i-1] == Y[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
			//fmt.Println(dp)
			res = maxInt(res, dp[i][j])
		}

	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	q = nextInt()

	for i := 0; i < q; i++ {
		X = nextStr()
		Y = nextStr()

		fmt.Println(lcs(X, Y))
	}
}

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 ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q; cin>>q;
    for(int i=0; i<q; i++){
        string x,y;
        cin>>x>>y;
        int nx=(int)x.size();
        int ny= (int)y.size();
        vector<vector<Int>> dp(nx+1,vector<Int>(ny+1,0));
        for(int i=0; i<(int)x.size(); i++){
            for(int j=0; j<(int)y.size(); j++){
                if(x[i]==y[j]){
                    dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
                }
                dp[i+1][j+1]=max({dp[i+1][j+1],dp[i][j+1],dp[i+1][j]});
            }
        }
        cout<<dp[nx][ny]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <string>
#include <utility>
using namespace std;

int n;
string a,b;


int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a >> b;
		int t[1010][1010] = {};
		for (int i = 0; i < a.length(); i++){
			for (int j = 0; j < b.length(); j++){
				if (i == 0 || j == 0)t[i][j] = 0;
				else if (a[i] == b[i]){
					t[i + 1][j + 1] = t[i][j] + 1;
				}
				else t[i + 1][j + 1] = max(t[i + 1][j], t[i][j + 1]);
			}
		}
		cout << t[a.length()][b.length()] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main() {
  int q;
  cin >> q;
  for (int i=0;i<q;++i) {
    string str1,str2;
    cin >> str1 >> str2;
    int size1 = str1.size();
    int size2 = str2.size();
    int matrix[size1+1][size2+1];
    for (int j=0;j<=size1;++j)
      matrix[j][0] = 0;
    for (int j=0;j<=size2;++j)
      matrix[0][j] = 0;
    for (int j=0;j<=size1;++j) {
      for (int k=0;k<=size2;++k) {
	if (j<=0||k<=0) {
	  matrix[j][k] = 0;
	}
	else if (str1[j]==str2[k]) {
	  matrix[j][k] = 1 + matrix[j-1][k-1];
	}
	else {
	  matrix[j][k] = max(matrix[j][k-1],matrix[j-1][k]);
	}
      }
    }
    cout << matrix[size1][size2] << endl;
  }
}

int max(int a,int b) {
  if (a>b)
    return a;
  else
    return b;
}

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

int main()
{
    int q;
    cin >> q;
    for (int ii = 0; ii < q; ii++)
    {
        string X, Y;
        cin >> X >> Y;
        int x = X.size();
        int y = Y.size();
        int dp[x + 1][y + 1];
        memset(dp, 0, sizeof(dp));
        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < y; j++)
            {
                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][y] << endl;
    }
}

C++: // Longest Common Subsequence

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
#define MAX 1001

int make_lcs(string x, string y) {
	int lcs[MAX][MAX] = {};
	x = ' ' + x;
	y = ' ' + y;
	for (unsigned int i=0;i<x.length();i++) {
	for (unsigned int j=0;j<y.length();j++) {
	if (i!=0 && j!=0) {
	if (x[i] == y[j]) {
	lcs[i][j] = lcs[i-1][j-1] + 1;
	}
	else {
	lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
	}
	}
	}
	}
	return lcs[x.length()-1][y.length()-1];
}
int main() {
	int n;
	string x,y;
	cin >> n;
	for (int k=0;k<n;k++) {
	cin >> x >> y;
	cout << make_lcs(x,y) << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

int dp[1010][1010] = {};



/*----------------------------------------------------------------*/
signed main(){

    int q;
	cin >> q;
	rep(iii,q){
		string s,t;
		cin >> s >> t;
		int sl = s.size();
		int tl = t.size();
		rep(i,sl)rep(j,tl)dp[i][j] = 0;
		rep(i,sl){
			rep(j,tl){
				if(s[i] == t[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[sl][tl] << endl;
	}
	
	

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://abc088.contest.atcoder.jp/tasks/abc088_d