#include <bits/stdc++.h>
using namespace std;
int n;
pair<long long int, long long int> a[300009];
long long int d[300009][3];
int main() {
  int i, j, k, l;
  int t, tv = 0;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
      scanf("%lld %lld", &a[i].first, &a[i].second);
      a[i].first += 5;
      d[i][0] = d[i][1] = d[i][2] = 1000000000000000009LL;
    }
    for (i = 1; i <= n; i++) {
      for (j = 0; j < 3; j++) {
        for (k = 0; k < 3; k++) {
          if (a[i - 1].first + j != a[i].first + k) {
            d[i][k] = min(d[i][k], d[i - 1][j] + k * a[i].second);
          }
        }
      }
    }
    long long int res = 1000000000000000009LL;
    for (i = 0; i < 3; i++) res = min(res, d[n][i]);
    printf("%lld\n", res);
  }
}
