#include <bits/stdc++.h>
using namespace std;
void printvector(vector<long long> v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
long long ans = 1000000;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = (y >> 1) % 1000000007;
    x = (x * x) % 1000000007;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  long long q;
  cin >> q;
  while (q--) {
    long long n, i, j, k, l;
    cin >> n;
    long long a[n][2];
    for (i = 0; i < n; i++) cin >> a[i][0] >> a[i][1];
    long long x[n][3];
    memset(x, -1, sizeof(x));
    x[0][0] = 0;
    x[0][1] = a[0][1];
    x[0][2] = a[0][1] * (long long)2;
    for (i = 1; i < n; i++) {
      for (l = 0; l <= 2; l++) {
        for (k = 0; k <= 2; k++) {
          if (a[i - 1][0] + k != a[i][0] + l && x[i - 1][k] != -1) {
            if (x[i][l] == -1)
              x[i][l] = x[i - 1][k] + a[i][1] * l;
            else
              x[i][l] = min(x[i][l], x[i - 1][k] + a[i][1] * l);
          }
        }
      }
    }
    long long ans = (long long)(1e18 + 1);
    for (k = 0; k < 3; k++)
      if (x[n - 1][k] != -1) ans = min(ans, x[n - 1][k]);
    cout << ans << endl;
  }
}
