#include <bits/stdc++.h>
const int maxn = 5000100;
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c;
  while (!isdigit(c = getchar()))
    ;
  do x = x * 10 + c - 48;
  while (isdigit(c = getchar()));
}
int64_t q, n, a[maxn], b[maxn], f[maxn][4], res;
int main() {
  read(q);
  for (int iTest = 1; iTest <= q; iTest++) {
    read(n);
    res = LLONG_MAX;
    for (int i = 1; i <= n; i++) {
      read(a[i]);
      read(b[i]);
    }
    for (int i = 1; i <= n; i++)
      for (int j = 0; j <= 2; j++) f[i][j] = LLONG_MAX;
    for (int i = 0; i <= 2; i++) f[1][i] = b[1] * i;
    for (int i = 2; i <= n; i++) {
      for (int j = 0; j <= 2; j++) {
        for (int k = 0; k <= 2; k++) {
          if (f[i - 1][k] == LLONG_MAX) continue;
          if (a[i] + j == a[i - 1] + k) continue;
          f[i][j] = min(f[i][j], f[i - 1][k] + b[i] * j);
        }
      }
    }
    for (int i = 0; i <= 2; i++) res = min(res, f[n][i]);
    cout << res << endl;
  }
}
