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<string>
#include<iostream>
using namespace std;

static const int N = 1000;

int max(int a, int b)
{
	if(a > b)
		return a;
	else 
		return b;
}
int lcs(string X, string Y)
{
	int c[N+1][N+1] = {0};
	int m = X.size();
	int n = Y.size();

	int max1 = 0;
	X = ' ' + X;
	Y = ' ' + Y;

	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]);
			}
			max1 = max(max1,c[i][j]);
		}
	}

	return max1;
}
int main()
{
	string a,b;
	int n;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		cin >> a >> b;
		printf("%d\n",lcs(a,b));
	}

	return 0;
}

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

int lcs(string X, string Y) {
	int dp[1000 + 1][1000 + 1];
	int max = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for (unsigned int i = 1; i <= X.length() - 1; i++)
		dp[i][0] = 0;

	for (unsigned int i = 1; i <= Y.length() - 1; i++)
		dp[0][i] = 0;

	for (unsigned int i = 1; i <= X.length() - 1; i++) {
		for (unsigned int j = 1; j <= Y.length() - 1; j++) {
			if (X[i] == Y[i])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else if (dp[i - 1][j] >= dp[i][j - 1])
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = dp[i][j - 1];

			max = (max < dp[i][j]) ? dp[i][j] : max;
        cout << "Hello" << endl;
		}
	}

	return max;
}

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

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

		cout << lcs(X, Y) << endl;
	}

	return 0;
}

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

using namespace std;

int dp[1010][1010];

int main(void) {
    int q;
    string x, y;
    cin >> q;

    while (cin >> x >> y) {
        memset(dp, 0, sizeof dp);

        int xs = x.size(), ys = y.size();
        for (int i = 1; i <= xs; i++)
            for (int j = 1; j <= ys; 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], max(dp[i][j - 1], dp[i - 1][j - 1]));
            }
            
        cout << dp[xs][ys] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
 
#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;
 
using namespace std;
int dp[1005][1005];
 
int main() {
    int n; cin >> n;
    REP(k, n){
        REP(i, 1005) REP(j, 1005) dp[i][j] = 0;
        string a, b;
        cin >> a >> b;
        REP(i, a.length()){
            string q = a.substr(i, 1);
            REP(j, b.length()){
                string t = b.substr(j, 1);
                if(q == t){
                    if(i == 0 || j == 0)
                        dp[i][j] = 1;
                    else
                        dp[i][j] = (dp[i-1][j] > dp[i][j-1]) ? max(dp[i-1][j-1] + 1, dp[i-1][j]) : max(dp[i-1][j-1] + 1, dp[i][j-1]);
                }
                else if (i != 0 && j != 0)
                    dp[i][j] = (dp[i-1][j] > dp[i][j-1]) ? dp[i-1][j] : dp[i][j-1];
                else if (i != 0)
                    dp[i][j] = dp[i-1][j];
                else
                    dp[i][j] = dp[i][j-1];
            }
        }
        cout << dp[a.length()-1][b.length()-1] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;
int dp[1000][1000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s1,s2;
	while(n--){
		cin>>s1>>s2;
		REP(i,s1.size())dp[i][0] = 0;
		REP(i,s2.size())dp[0][i] = 0;
		FOR(i,1,s1.size()+1){
			FOR(j,1,s2.size()+1){
				if(s1[i] == s2[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[s1.size()][s2.size()] << endl;
	}
  return 0;
}

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.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 = 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;
    }
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
  int N,X,Y;
  char x[1024],y[1024];
  int dp[1024][1024];
  scanf("%d",&N);
  while(N--){
    scanf("%s%s", x, y);
    X = strlen(x); Y = strlen(y);
    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] = dp[i][j]+1;
	else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
      }
    }
    printf("%d\n", dp[X][Y]);
  }
  return 0;
}