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 <cstdio>
#include <cstring>

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

int main(void){
  char x[1005]={0};
  char y[1005]={0};
  int set=0;
  int dp[1005][1005]={0};
  /*dp[i][j]は、xのi文字目とyのj文字目での最長部分列*/
  scanf("%d",&set);
  int p=0,i=0,j=0;;
  for(p=0;p<set;p++){
    scanf("%s%s",x,y);
    int xl,yl;
    xl=strlen(x);yl=strlen(y);
    int ma,mb,mc;
    for(i=1;i<xl+1;i++){
      for(j=1;j<yl+1;j++){
	ma=dp[i][j-1];
	mb=dp[i-1][j];
	mc=dp[i-1][j-1];
	if(x[i-1]==y[j-1])mc++;
	//dp[i][j]= ma<mb ? (mb<mc ? mc : mb) : ma;
	dp[i][j]= max(ma,max(mb,mc));
      }
    }
    printf("%d\n",dp[xl][yl]);
  }
  return 0;
}

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

string X;
string Y;

int calc(int x_s, int x, int y, int length){
    if (X[x] == '\0') return length;
    int y_ = Y.find(X[x], y);
    if (y_ == string::npos) {
        if ((Y[y+1] == '\0')) {
            return max(length, calc(x_s + 1, x_s + 1, 0, 0));
        }
        return max(length, calc(x_s, x, y + 1, length));
    }
    return calc(x_s, x + 1, y_ + 1, length + 1);
}

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

    return 0;
}

C++: #include <iostream>
#include <string>
#include <utility>
using namespace std;
#define MAXQ 150
#define MAXL 1000

int main(){
    int n; cin >> n;
    pair<string, string> pairs[MAXQ];
    for(int i=0; i<n; ++i){
        cin >> pairs[i].first >> pairs[i].second;
    }
    
    for(int i=0; i<n; ++i){
        string str1, str2;
        str1 = pairs[i].first;
        str2 = pairs[i].second;
        int dp[MAXL][MAXL];
        for(int r=0; r<=str1.size(); ++r){
            dp[r][0] = 0;
        }
        for(int c=0; c<=str2.size(); ++c){
            dp[0][c] = 0;
        }
        for(int r=1; r<=str1.size(); ++r){
            for(int c=1; c<=str2.size(); ++c){
                int d = 0;
                if (str1[r] == str2[c]) d++;
                dp[r][c] = max(dp[r-1][c-1]+d, max(dp[r-1][c], dp[r][c-1]));
            }
        }
        cout << dp[str1.size()][str2.size()] << endl;
    }
}

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

using ll = long long;

int main() {
    //dp[i][j] Xのi文字目までとYのj文字目までのLCS
    int q;
    cin >> q;
    rep(i, q) {
        string X, Y;
        cin >> X >> Y;
        int m = X.size(), n = Y.size();
        vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
        rep(j, m) {
            rep(k, n) {
                if (X[j] == Y[k]) {
                    dp[j + 1][k + 1] = dp[j][k] + 1;
                } else {
                    dp[j + 1][k + 1] = max(dp[j][k + 1], dp[j + 1][k]);
                }
            }
        }
        cout << dp[m][n] << "\n";
    }
}

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

int main(){
    int N;
    cin >> N;
    for(int c=0; c<N; ++c){
        string X,Y;
        cin >> X >> Y;

        int DP[1024][1024] = {};

        for(int i=0;i<=(int)X.size();++i){
            for(int j=0;j<=(int)Y.size();++j){
                if(X[i] == Y[j]){ // X???i???????????¨Y???j??????????????????????????????
                    DP[i][j] = DP[i-1][j-1] + 1;
                } else {
                    DP[i][j] = max(DP[i-1][j], DP[i][j-1]);
                }
            }
        }
        cout << DP[(int)X.size()][(int)Y.size()] << endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << ((sizeof...(tail)!=0)?" ":""); print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a << ((&a!=&vec.back())?" ":""); } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

int dp[1010][1010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    rep(_, n) {
        string s, t; cin >> s >> t;
        memset(dp, 0, sizeof(dp));
        int n = s.length(), m = t.length();
        rep(i, n) rep(j, m) {
            char a = s[i], b = t[j];
            if (a==b) 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[n][m] << 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];
	int m = X.xize();
	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() {
	
	string s1, s2;
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s1 >> s2;
	    cout << lcs(s1, s2) << end1;
	}
	
	return 0;
}