#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3fffffff;
long long q, n, dp[maxn][3];
struct Node {
  long long h, cost;
} node[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> node[i].h >> node[i].cost;
      for (int j = 0; j < 3; j++) dp[i][j] = LLONG_MAX;
    }
    dp[1][0] = 0;
    dp[1][1] = node[1].cost;
    dp[1][2] = 2 * node[1].cost;
    for (int i = 2; i <= n; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          if (node[i - 1].h + j != node[i].h + k) {
            dp[i][k] = min(dp[i][k], dp[i - 1][j] + k * node[i].cost);
          }
        }
      }
    }
    cout << min(dp[n][0], min(dp[n][1], dp[n][2])) << endl;
  }
  return ~~(0 - 0);
}
