Go: // AOJ ALDS1_10_C: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

package main

import (
	"fmt"
)

func main() {
	var dataNum int
	var s1, s2 string

	fmt.Scanf("%d", &dataNum)

	for i := 0; i < dataNum; i++ {
		fmt.Scanf("%s", &s1)
		fmt.Scanf("%s", &s2)

		lcs := make([][]int, len(s1)+1)
		for j := 0; j < len(s1)+1; j++ {
			lcs[j] = make([]int, len(s2)+1)
		}

		for m, vs1 := range s1 {
			for n, vs2 := range s2 {
				if vs1 == vs2 {
					lcs[m+1][n+1] = lcs[m][n] + 1
				} else if lcs[m+1][n] > lcs[m][n+1] {
					lcs[m+1][n+1] = lcs[m+1][n]
				} else {
					lcs[m+1][n+1] = lcs[m][n+1]
				}
			}
		}

		// Answer
		fmt.Println(lcs[len(s1)][len(s2)])
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;
static const int N=1000;
int lcs(string X, string Y){
    int m=X.size();
    int n=Y.size();
    int c[N+1][N+1];
    int maxl=0;
    X=' '+X;
    Y=' '+Y;
    int i,j;
    for(i=1;i<=m;i++)c[i][0]=0;
    for(j=1;j<=n;j++)c[0][j]=0;

    for(i=1;i<=m;i++){
        for(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][j-1],c[i-1][j]);
            }
            maxl=max(maxl,c[i][j]);
        }
    }
    return maxl;
}
int main()
{
    int n;
    string s1,s2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s1>>s2;
        cout<<lcs(s1,s2)<<endl;
    }

    return 0;
}

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


int main()
{
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        string x, y;
        cin >> x >> y;
        int c[1001][1001];
        for(int j = 0; j <= (int)x.size(); j++) c[j][0] = 0;
        for(int j = 0; j <= (int)y.size(); j++) c[0][j] = 0;
        for(int j = 1; j <= (int)x.size(); j++){
            for(int k = 1; k <= (int)y.size(); k++){
                if(x[j - 1] == y[k - 1]) c[j][k] = c[j - 1][k - 1] + 1;
                else c[j][k] = max(c[j - 1][k],c[j][k - 1]);
                
            
            }
        
        }
        cout << c[x.size()][y.size()] << endl;
        
        
        
    }
    
    
    return 0;
}

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

#define MAX 1000

int lcs(string x, string y) {
  int c[MAX + 1][MAX + 1];
  int m = x.size();
  int n = y.size();
  int maxl = 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]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }

  return maxl;
}

int main() {
  string s1, s2;
  int q;
  cin >> q;

  for ( int i = 0; i < q; i++ ) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << 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], maxl = 0, i, j;
  int m = x.size();
  int n = y.size();

  x = ' ' + x;
  y = ' ' + y;
 
  for(i = 1; i <= m; i++) c[i][0] = 0;
  for(i = 0; i <= n; i++) c[0][i] = 0;

  for(i = 1; i <= m; i++){
    for(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 x, y;
  int q, i;

  cin >> q;
  
  for(i = 0; i < q; i++){
    cin >> x >> y;
    cout << lcs(x, y) << endl;
  }
  return 0;
}

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

int lcs(string X, string Y) {
    int c[1001][1001];
    int m = X.size();
    int n = Y.size();
    X = ' ' + X;
    Y = ' ' + Y;
    int maxl = 0;
    for (int i = 0; i < m + 1; i++) c[i][0] = 0;
    for (int j = 1; j < n + 1; j++) c[0][j] = 0;
    
    for (int i = 1; i < m + 1; i++) {
        for (int j = 1; j < n + 1; 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>
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 = 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++: 
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

#define LEN_MAX (1000)
DWORD dpLCS[LEN_MAX + 1][LEN_MAX + 1];

void initDpTable(DWORD maxI, DWORD maxJ)
{
	REP(i, 0, maxI + 1) {
		REP(j, 0, maxJ + 1) {
			dpLCS[i][j] = 0;
		}
	}

}

void solve_main()
{
	DWORD dwNum;
	string str1, str2;
	cin >> dwNum;
	REP(loop, 0, dwNum) {
		cin >> str1;
		cin >> str2;
		initDpTable(str1.length(), str2.length());

		REP(i, 1, (str1.length() + 1)) {
			REP(j, 1, (str2.length() + 1)) {
				if (str1[i - 1] == str2[j - 1]) {
					dpLCS[i][j] = dpLCS[i - 1] [j - 1] + 1;
				} else {
					dpLCS[i][j] = max(dpLCS[i - 1][j], dpLCS[i][j - 1]);
				}
			}
		}
		cout << dpLCS[str1.length()][str2.length()] << endl;
	}
}

int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}

C++: //   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<random>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int q;
  cin >> q;
  while(q--) {
    string s,t;
    cin >> s >> t;
    int dp[s.size()+5][t.size()+5]={};
    for(int i=1; i<=s.size(); i++) {
      for(int j=1; j<=t.size(); j++) {
        if(s[i-1]==t[j-1]) {
          dp[i][j]=dp[i-1][j-1]+1;
        }
        else {
          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
      }
    }
    cout << dp[s.size()][t.size()] << endl;
  }
 }