Go: package main

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

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

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

int main(){
  int n;
  char x[1000],y[1000];
  int dp[1001][1001];
  //load n;
  cin >>n;
  for(int i=0;i<n;i++){
    //load string
    scanf("%s",x);
    scanf("%s",y);
    //dp
    for(int j=0;j<strlen(x);j++){
      for(int k=0;k<strlen(y);k++){
	if(x[j]==y[k]){
	  dp[j+1][k+1]=dp[j][k]+1;
	}

	else{
	  if(dp[j][k+1]>dp[j+1][k]){
	    dp[j+1][k+1]=dp[j][k+1];
	  }

	  else{
	    dp[j+1][k+1]=dp[j+1][k];
	  }


	}
      }
    }
    cout <<dp[strlen(x)][strlen(y)]<<endl;
  }



  return 0;
}

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

#define N 1001
int A[N][N];

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

    string target1;
    string target2;
    for (int i = 0; i < q; i++) {
        cin >> target1;
        cin >> target2;
        int l1 = target1.length();
        int l2 = target2.length();
        for (int m = 0; m <= l1; m++) {
            A[m][0] = 0;
        }
        for (int n = 0; n <= l2; n++) {
            A[0][n] = 0;
        }

        target1 = ' ' +  target1;
        target2 = ' ' +  target2;

        for (int m = 1; m <= l1; m++) {
            for (int n = 1; n <= l2; n++) {
                if (target1[m] == target2[n]) {
                    A[m][n] = A[m-1][n-1] + 1;
                } else {
                    A[m][n] = max(A[m-1][n], A[m][n-1]);
                }
            }
        }

        cout << A[l1][l2] << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>

#define iter(n) for(int iter_var = 0; iter_var < n; iter_var += 1)
#define rep(i, s, n) for(int i = s; i < n; i += 1)
#define lli long long int
#define INF 1e9
#define MOD 1000000007

using namespace std;

int lcs(string s, string t){

  int s_size = s.size();
  int t_size = t.size();
  vector<vector<int>> dp(s_size + 1, vector<int>(t_size + 1, 0));

  rep(i, 1, s_size + 1) rep(j, 1, t_size + 1){
    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]);
    }
  }

  return dp[s_size][t_size];
}

int main(){

  int n; cin >> n;
  iter(n){
    string s, t; cin >> s >> t;
    cout << lcs(s, t) << endl;
  }

  return 0;
}

C++: #define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <iterator>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cfloat>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <stdexcept>

typedef long long ll;
typedef unsigned int ui;
typedef unsigned short us;
typedef unsigned long long ull;

template <typename T>
std::ostream& operator<< (std::ostream& out, const std::vector<std::vector<T>>& v) {
  if (!v.empty()) {
    for (std::vector<T> v2 : v) {
      std::copy(v2.begin(), v2.end(), std::ostream_iterator<T>(out, ", "));
      out << "\b\b \n";
    }
  }
  return out;
}
template <typename T>
std::ostream& operator<< (std::ostream& out, const std::vector<T>& v) {
  if ( !v.empty() ) {
    std::copy (v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
    out << "\b\b ";
  }
  return out;
}

using namespace std;

namespace my {
  class LCS
  {
  public:
    LCS() = default;
    ~LCS() = default;

  private:

  };
}

int main(int argc, const char * argv[]) {
  int q;
  cin >> q;
  vector<string> x;
  vector<string> y;
  for (size_t i = 0; i < q; i++)
  {
    string temp;
    cin >> temp;
    x.push_back(temp);
    cin >> temp;
    y.push_back(temp);
  }
  
  
  
  for (size_t i = 0; i < q; i++)
  {
    size_t x_length = x[i].length();
    size_t y_length = y[i].length();
    size_t max_length = min(x_length, y_length);
    vector<int> length_y_nanmoji(1, y_length);
    map<char, vector<int>> y_nanmoji;
    for (size_t j = 0; j < x_length; j++)
    {
      char x_char = x[i][j];
      if (y_nanmoji.find(x_char) == y_nanmoji.end()) {
        size_t count = 0;
        bool is_looped = false;
        do
        {
          count = y[i].find(x_char, count);
          if (count >= y_length) {
            if (!is_looped) {
              y_nanmoji[x_char].push_back(-1);
            }
            break;
          }
          else {
            y_nanmoji[x_char].push_back((int)count);
            count++;
          }
        } while (is_looped = true, true);
      }

      auto y_nanmoji_now = y_nanmoji[x_char];
      if (y_nanmoji_now[0] == -1) {
        continue;
      }
      for(int l = (int)y_nanmoji_now.size() - 1; l >= 0; l--)
      {
        int val = y_nanmoji_now[l];
        bool is_done = false;
        for (int k = 0; k < (int)length_y_nanmoji.size(); k++)
        {
          if (length_y_nanmoji[k] >= val) {
            length_y_nanmoji[k] = val;
            is_done = true;
            break;
          }
        }
        if (!is_done) {
          length_y_nanmoji.push_back(val);
        }
      }

    }
    int kotae = length_y_nanmoji[0] >= y_length ? 0 : length_y_nanmoji.size();
    cout << kotae << 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;
}