#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1000000007;
const int nn = 300005;
int n, m, k, t;
long long f[nn][3];
int a[nn], b[nn];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
      scanf("%d%d", &a[i], &b[i]);
      for (int j = 0; j < 3; ++j) {
        f[i][j] = inf;
      }
    }
    f[1][0] = 0;
    f[1][1] = b[1];
    f[1][2] = b[1] * 2;
    for (int i = 2; i <= n; ++i) {
      for (int j = 0; j <= 2; ++j) {
        for (int k = 0; k <= 2; ++k) {
          if (a[i] + j == a[i - 1] + k) continue;
          f[i][j] = min(f[i][j], f[i - 1][k] + j * b[i]);
        }
      }
    }
    long long ans = inf;
    for (int j = 0; j <= 2; ++j) {
      ans = min(ans, f[n][j]);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
