Go: package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    //cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int data_num; cin >> data_num;
    int ans[data_num];
    REP(rep,data_num){
        string T,S;
        cin >> T; cin >> S;
        vector<vector<int> > dp(T.size()+1, vector<int>(S.size()+1, 0));
        REP(i,T.size()){
            REP(j,S.size()){
                if(T[i] == S[j]) {dp[i+1][j+1] = dp[i][j] + 1;}
                else {dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);}
            }
        }
        ans[rep] = dp[T.size()][S.size()];
    }

    REP(i,data_num){
        cout << ans[i] << endl;
    }
}

C++: #include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int dp[1010][1010];

int main(void) {
    int n;
    cin >> n;
    while (n--) {
        string a, b;
        cin >> a;
        cin >> b;
        for (int i = 0; i < 1010; i++) {
            for (int j = 0; j < 1010; j++) {
                dp[i][j] = 0;
            }
        }
        for (int i = 1; i <= a.size(); i++) {
            for (int j = 1; j <= b.size(); j++) {
                if (a[i-1] == b[j-1]) {
                    dp[i][j] = max(dp[i-1][j-1] + 1, max(dp[i-1][j], dp[i][j-1]));
                } else {
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
                }
//                cout << dp[i][j] << "  ";
            }
//            cout << endl;
        }
        cout << dp[a.size()][b.size()] << endl;
    }
    return 0;
}

C++: //By Vlgd
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int dp[1001][1001];
void solve(){
	int m=0;
	int n1=s1.size(),n2=s2.size();
	s1=' '+s1;s2=' '+s2;
	for (int i=0;i<=n1;i++) dp[i][0]=0;
	for (int i=0;i<=n2;i++) dp[0][i]=0;
	for (int i=1;i<=n1;i++)
		for (int j=1;j<=n2;j++){
			if (s1[i]==s2[j]) dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
	printf("%d\n",dp[n1][n2]);
}
main(){
	int q;scanf("%d",&q);
	for (int i=0;i<q;i++){
		cin>>s1>>s2;
		solve();
	}
}

C++: #include<iostream>
#include<string>
int main(){
  int n;
  std::string x,y;
  std::cin>>n;
  int a[1000][1000];
  int b[n];

  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<1000;j++){
      for(int k=0;k<1000;k++){
	a[j][k]=0;
      }
    }
    for(int j=0;j<x.size();j++){
      for(int k=0;k<y.size();k++){
	if(x[j]==y[k]){
	  a[j][k]=a[j-1][k-1]+1;
	}else{
	  if(a[j-1][k]>a[j][k-1]){
	    a[j][k]=a[j-1][k];
	  }else{
	    a[j][k]=a[j][k-1];
	  }
	}
      }
    }
    b[i]=a[x.size()-1][y.size()-1];
  }

  for(int i=0;i<n;i++){
  std::cout<<b[i]<<"\n";
  }

  return 0;
}

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


int main(int argc, char *argv[]){
  int n;
  cin >> n;
  for (int r = 0; r < n; r++) {

    string x, y;
    cin >> x >> y;
    int dp[y.length() + 1][x.length() + 1];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < y.length(); i++) {
      for (int j = 0; j < x.length(); j++) {
        if(y[i] == x[j]){
          dp[i + 1][j + 1] = dp[i][j] + 1;
        }else{
          dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        }
      }
    }
    std::cout << dp[y.length()][x.length()] << std::endl;
  }
  return 0;
}

C++: #include<iostream>
#include <cstdlib>
#include<list>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<stack>
#define MAX 101
using namespace std;
int main() {
	int n; cin >> n;
	string x, y; int data[MAX][MAX] = {0,0};
	for (int d = 0; d <n; d++)
	{
		cin >> x >> y;
		for (int i = 0; i < y.size(); i++)
		{
			for (int j = 0; j < x.size(); j++)
			{
				if (y[i] == x[j]) {
					data[j + 1][i + 1] = data[j][i] + 1;
				}
				else {
					data[j + 1][i + 1] = max(data[j + 1][i], data[j][i + 1]);
				}
			}
		}
		cout << data[x.size()][y.size()]<<endl;
	}
	
	return 0;
}