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>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int q;
string x, y;
int dp[1111][1111];

void print() {
   for (int i = 0; i <= x.size(); i++) {
      for (int j = 0; j <= y.size(); j++) {
         cout << dp[i][j];
      }
      puts("");
   }
}

void solve() {
   int n = x.size() - 1, m = y.size() - 1;
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
         if (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[n][m] << endl;
}

int main() {
   cin >> q;
   while (q--) {
      fill(dp[0], dp[1111], 0);
      cin >> x >> y;
      x = "#" + x, y = "#" + y;
      solve();
   }

   return 0;
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N=55555;
bool is_prime[MAX_N];
int prime[MAX_N];
int main(){
  int n;
  cin>>n;
  int dp[1001][1001];
  for(int nn=0;nn<n;nn++){
    string s1,s2;
    cin>>s1>>s2;
    for(int i=0;i<1001;i++)fill(dp[i],dp[i]+1001,0);
    for(int i=0;i<s1.size();i++){
      for(int j=0;j<s2.size();j++){
        if(s1[i]==s2[j]) dp[i+1][j+1]=max(dp[i][j]+1,max(dp[i][j+1],dp[i+1][j]));
        else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
      }
    }
    cout<<dp[s1.size()][s2.size()]<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>


using namespace std;int n[1003][1003]={};
int main(){

string A,B;
int N;
cin>>N;
for(int I=0;I<N;I++){
	cin>>A;cin>>B;

	
	int max=0;
	for(int i=0;i<(int)A.size();i++)
		for(int j=0;j<(int)B.size();j++)
			{
				
				if(A[i]==B[j])n[i+1][j+1]=n[i][j]+1;
				else{
					n[i+1][j+1]=n[i+1][j];
				if(n[i][j+1]>n[i+1][j])n[i+1][j+1]=n[i][j+1];
				}
				
		}
		/*
		for(int i=0;i<=(int)A.size();i++){cout<<endl;
		for(int j=0;j<=(int)B.size();j++){cout<<n[i][j];}}
		*/
		for(int i=A.size()+0;i>=0;i--){int c=0;int y=i;
		for(int j=B.size()+0;j>=0;j--)
		{if(n[y][j]==n[y-1][j-1]+1&&y>0){y--;c++;
		}
	}
		if(max<c)max=c;
		}
		cout<<max<<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 = 0; 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) << endl;
	}

    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int n;
string x,y;

vector<vector<int> > q(1001,vector<int>(1001,-1));

int search(int i,int j){
  int ans;
  if(i<0 || j<0) return 0;
  if(q[i][j] != -1) return q[i][j];
  if( x[i] == y[j] ){
    ans=max( {search(i-1,j-1)+1,search(i-1,j),search(i,j-1)} );
    q[i][j]=ans;
    return ans;
  }
  else{
    ans=max( search(i-1,j),search(i,j-1) );
    q[i][j]=ans;
    return ans;
  }

}


int main(void){

  cin>>n;

  for(int i=0;i<n;i++){
    cin>>x;
    cin>>y;

    for(int ix=0;ix<1001;ix++){
      for(int iy=0;iy<1001;iy++){
        q[ix][iy]=-1;
      }
    }

    search( x.size(),y.size() );
    cout << q[x.size()-1][y.size()-1] << endl;
  }



  return 0;
}