#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1e9;
const int N = 3e5 + 5;
int n;
int a[N], b[N];
long long f[N][3];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]);
    for (int i = 1; i <= n; i++)
      for (int j = 0; j < 3; j++) f[i][j] = INF;
    for (int i = 1; i <= n; i++) {
      for (int add = 0; add < 3; add++) {
        for (int prevAdd = 0; prevAdd < 3; prevAdd++) {
          if (a[i - 1] + prevAdd == a[i] + add) continue;
          f[i][add] = min(f[i][add], f[i - 1][prevAdd] + 1LL * add * b[i]);
        }
      }
    }
    long long res = INF;
    for (int i = 0; i < 3; i++) res = min(res, f[n][i]);
    printf("%lld\n", res);
  }
}
