#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
long long a[300005], b[300005];
long long dp[300005][3];
int main() {
  long long d1, d2, t1, t2;
  int q;
  scanf("%ld", &q);
  while (q--) {
    int n;
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
      scanf("%ld%ld", a + i, b + i);
      dp[i][0] = dp[i][1] = dp[i][2] = inf;
    }
    dp[0][0] = 0;
    dp[0][1] = b[0];
    dp[0][2] = b[0] * 2;
    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        long long h = a[i - 1] + j;
        for (int k = 0; k < 3; k++) {
          if (h != a[i] + k) dp[i][k] = min(dp[i][k], dp[i - 1][j] + k * b[i]);
        }
      }
    }
    cout << min(min(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl;
  }
}
