Go: package main

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

func max(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

/*********************************************************************
長さmの列X_(m)と長さnの列Y_(n)の最長共通部分列LCSは、
	(1)X[m] == Y[n]ならば、X_(m-1)とY_(n-1)のLCSにX[m]を繋げたもの
	(2)X[m] != Y[n]ならば、X_(m-1)とY_(n)のLCSもしくはX_(m)とY_(n-1)のLCS
	のいずれかのうち長い方

c[m+1][n+1]：c[i][j]にX_(i)とY_(j)のLCSの長さを格納する二次元配列
*********************************************************************/

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s1 := scanner.Text()
		scanner.Scan()
		s2 := scanner.Text()
		s1, s2 = s1 + " ", s2 + " "
		c := make([][]int, len(s1))
		for i := range c {
			c[i] = make([]int, len(s2))
		}

		LCS := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					c[i][j] = c[i-1][j-1] + 1
				} else {
					c[i][j] = max(c[i-1][j], c[i][j-1])
				}
				LCS = max(LCS, c[i][j])
			}
		}
		fmt.Println(LCS)
	}
}

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

using namespace std;

int maxa[1000];
int main(){
  int n;
  int k;
  int count;
  cin>>n;
  char X[1001];
  char Y[1001];
  for(int i=0;i<n;i++){
    cin>>X;
    cin>>Y;
    k=0;
    for(int a=0;X[a]!='\0';a++){
    count=0;
      for(int s=a;X[s]!='\0';s++){
	for(int j=k;Y[j]!='\0';j++){
	  if(X[s]==Y[j]){
	    count++;
	    k=j;
	    break;
	  }
	}
      }
      if(maxa[i]<count)maxa[i]=count;
    }
  }
  for(int i=0;i<n;i++){
    cout<<maxa[i]<<endl;
  }
  
  return 0;
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {
  int q;
  cin >> q;
  rep(k, q) {
    string x, y;
    cin >> x >> y;
    int m = x.size();
    int n = y.size();
    vector<vector<int> > dp(m + 1, vector<int>(n + 1, 0));
    rep(i, m) {
      rep(j, n) {
        if (x[i] == y[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
        } else {
          dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        }
      }
    }
    cout << dp[m][n] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}



int main(){
	int q;
	cin>>q;
	vector<string> s0(q),t0(q);
	rep(i,q){
		cin>>s0[i]>>t0[i];
	}
	rep(i,q){

	string s,t;
	s=s0[i];
	t=t0[i];
	vector<vector<int>> a(s.size());
	rep(i,s.size()){
		a[i].resize(t.size());
		rep(j,t.size()){
			if(i==0 && j==0){
				if(s[0]==t[0]) a[0][0]=1;
				else a[0][0]=0;
			}else if(j==0){
				if(s[i]==t[0]) a[i][0]=1;
				else a[i][0]=a[i-1][0];
			}else if(i==0){
				if(s[0]==t[j]) a[0][j]=1;
				else a[0][j]=a[0][j-1];
			}else{
				if(s[i]==t[j]) a[i][j]=a[i-1][j-1]+1;
				else a[i][j]=max(a[i][j-1],a[i-1][j]);
			}
		}
	}
	cout<<a[s.size()-1][t.size()-1]<<endl;
	}
}

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

int main(void){
    int q; cin >> q;
    int dp[1001][1001];
    for(int i = 0; i < 1001; i++) dp[0][i] = dp[i][0] = 0;

    for(int i = 0; i < q; i++){
        string a, b; cin >> a >> b;
        int len_a = (int)a.size(), len_b = (int)b.size();
        for(int j = 1; j <= len_a; j++){
            for(int k = 1; k <= len_b; k++){
                if(a[j-1]==b[k-1]) dp[j][k] = dp[j-1][k-1] + 1;
                else dp[j][k] = max(dp[j-1][k], dp[j][k-1]);
                // cout << "(j, k) = " << j << ", " << k << ": dp = " << dp[j][k] << '\n';
            }
        }

        cout << dp[len_a][len_b] << '\n';
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define N 1050
int lc(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(){
  int n;cin>>n;
  while(n--){
    string s,v;cin>>s>>v;
    cout<<lc(s,v)<<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=0;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>
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++: // https://onlinejudge.u-aizu.ac.jp/status/users/uzi7215/submissions/1/ALDS1_10_C/judge/3551530/Python3
#include <iostream>
#include <vector>

int main(){
  int q;
  std::cin >> q;
  std::vector<std::string> x_list, y_list;
  for( int i=0; i<q; i++ ){
    std::string input;
    std::cin >> input;
    x_list.push_back( input );
    std::cin >> input;
    y_list.push_back( input );
  }

  for( int k=0; k<q; k++ ){
    std::string x = x_list[k];
    int m = x.size() + 1;
    std::string y = y_list[k];
    int n = y.size() + 1;
    std::vector< std::vector<int> > c(m, std::vector<int>(n, 0));

	int i, j;
    for( i=1; i<m; i++ ){
      for( j=1; j<n; j++ ){
      	if( i==0 or j==0){
      		c[i][j] = 0;
		}else if( x[i-1] == y[j-1] ){
          c[i][j] = c[i-1][j-1] + 1;
        }else{
          c[i][j] = std::max( c[i-1][j], c[i][j-1] );
        } 
      }
    }
    std::cout << c[m-1][n-1] << std::endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespase 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 ( i = 0; i < n; i++ ){
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << sndl;
    }
    
    return 0;
    
}