Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func f() {
	var S, T string
	fmt.Scan(&S)
	fmt.Scan(&T)
	lenS, lenT := len(S), len(T)
	dp := make([][]int, lenS+1)
	for i:=0; i<lenS+1; i++ {
		dp[i] = make([]int, lenT+1)
	}
	for i:=1; i<lenS+1; i++ {
		for j:=1; j<lenT+1; j++ {
			if S[i-1] == T[j-1] {
				dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
			} else {
				dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
			}
		}
	}
	fmt.Println(dp[lenS][lenT])
}

func main(){
	var n int 
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		f()
	}
}

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

using namespace std;

int results[1001][1001];

int lcs(string x, string y)
{
    // initialize
    for (int i = 0; i < 1001; ++i) {
        for (int j = 0; j < 1001; ++j)
            results[i][j] = 0;
    }

    int maxlcs = 0;
    for (int i = 1; i <= x.length(); ++i) {
        for (int j = 1; j <= y.length(); ++j) {
            if (x[i-1] == y[j-1])
                results[i][j] = results[i-1][j-1] + 1;
            else
                results[i][j] = max(results[i-1][j], results[i][j-1]);

            if (maxlcs < results[i][j])
                maxlcs = results[i][j];
        }
    }
    return maxlcs;
}

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

    vector<string> x(n);
    vector<string> y(n);
    for (int i = 0; i < n; ++i)
        cin >> x[i] >> y[i];

    for (int i = 0; i < n; ++i)
        cout << lcs(x[i], y[i]) << '\n';
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main() {
    int q;
    cin >> q;
    
    rep(i,q) {
        string X,Y;
        cin >> X >> Y;
        int lX=X.size(), lY=Y.size();
        vector<vector<int>> dp(lX+1, vector<int>(lY+1,0));

        rep(i,lX)
            rep(j,lY)
                if(X.at(i) == Y.at(j))
                    dp.at(i+1).at(j+1) = dp.at(i).at(j)+1;
                else
                    dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j), dp.at(i).at(j+1));

        cout << dp.at(lX).at(lY) << endl;
    }
}

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 <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define MAX 150
void solve(void);
int q,count[MAX][MAX]={},xlength,ylength;
char X[MAX],Y[MAX];

void solve(void){
  int i,j;

  for(i=1;i<=strlen(X);i++){
    for(j=1;j<=strlen(Y);j++){
      if(X[i-1]==Y[j-1]) count[i][j]=count[i-1][j-1]+1;
      else if(count[i-1][j]>=count[i][j-1]) count[i][j]=count[i-1][j];
      else count[i][j]=count[i][j-1];
    }
  }

  xlength=strlen(X);
  ylength=strlen(Y);
}
    

int main()
{
  int i;
  
  scanf("%d",&q);

  for(i=1;i<=q;i++){
    scanf("%s",X);
    scanf("%s",Y);
    solve();
    printf("%d\n",count[xlength][ylength]);
  }

  /*for(i=0;i<q;i++){
    printf("%d\n",count[][]);
    }*/

  return 0;
}

C++: #include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950

void C (string x, string y){
    int p = x.size() ;
    int q = y.size() ;
    vector<vector<int>> dp (p + 1 , vector<int> (q + 1)) ;
    rep(i, p){
        rep(j, q){
            if(x.at(i) == y.at(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[p][q] << endl;
}

int main() {
    int n ; 
    cin >> n ;
    vector<string> s (n) ;
    vector<string> t (n);
    rep(i, n){
        cin >> s[i] ;
        cin >> t[i] ;
    }
    rep(k, n){
        C(s[k], t[k])  ;
    }
}

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

int main()
{
  std::vector<std::string> x;
  std::vector<std::string> y;
  std::vector<std::string> z;

  int n;
  std::string str1;
  std::string str2;
  std::string str_z;
  std::cin>>n;
  if(n>150){
   std::cout<<"EEROR\n";
   }
  for(int k=0;k<n;k++){
    std::cin>>str1;
    x.push_back(str1);
    std::cin>>str2;
    y.push_back(str2);
  }
  /*for(int i=0;i<n;i++){
    for(int j=0;j<x[i].size();j++){
      std::cout<<x[i][j]<<":";
      if(j==x[i].size()-1){
	std::cout<<"\n";
      }
    }   
  } 
  for(int i=0;i<n;i++){
    for(int j=0;j<y[i].size();j++){
      std::cout<<y[i][j]<<":";
      if(j==y[i].size()-1){
	std::cout<<"\n";
      }
    }
  }
  std::cout<<x[0].size()<<" "<<y[0].size()<<"\n";
  std::cout<<x[0][2]<<"\n";
  */
  int count[n]={0};
  for(int i=0;i<n;i++){
    int xl=0,yl=0,tmp=0,judege=0;
    if(x[i].size()<=y[i].size()){
      while(judege==0){
	//std::cout<<i<<" xl:"<<xl<<" yl:"<<yl<<"\n";
	if(xl==x[i].size()&&yl==y[i].size()){
	  judege=-1;
	}else if(yl==y[i].size()){
	  yl=tmp;
	  xl++;
	}else if(x[i][xl]==y[i][yl]){
	  count[i]++;
	  str_z=x[i][xl];
	  z.push_back(str_z);
	  xl++;
	  yl++;
	  tmp=yl;
	}else{
	  yl++;
	}
      }
    }else{
     while(judege==0){
	//std::cout<<i<<" xl:"<<xl<<" yl:"<<yl<<"\n";
	if(xl==x[i].size()&&yl==y[i].size()){
	  judege=-1;
	}else if(xl==x[i].size()){
	  xl=tmp;
	  yl++;
	}else if(x[i][xl]==y[i][yl]){
	  count[i]++;
	  str_z=x[i][xl];
	  z.push_back(str_z);
	  xl++;
	  yl++;
	  tmp=xl;
	}else{
	  xl++;
	}
      } 

    }
  }
  for(int i=0;i<n;i++){
    std::cout<<count[i]<<"\n";
    /*for(int j=0;j<z.size();j++){
      std::cout<<z[j];
    } 
    std::cout<<"\n";
    */
  }


  return 0;
}