#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
struct li {
  long long cost;
  long long len;
};
li l[300005];
long long dp[300005][3];
long long n;
void init() {
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 3; j++) {
      dp[i][j] = LLONG_MAX;
    }
  }
}
signed main() {
  long long q;
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld", &n);
    init();
    for (long long i = 0; i < n; i++) scanf("%lld%lld", &l[i].len, &l[i].cost);
    dp[0][0] = 0;
    dp[0][1] = l[0].cost;
    dp[0][2] = l[0].cost * 2;
    for (long long i = 1; i < n; i++) {
      for (long long j = 0; j < 3; j++) {
        long long temp = l[i].len + j;
        dp[i][j] = LLONG_MAX;
        for (long long k = 0; k < 3; k++) {
          if (l[i - 1].len + k != temp) {
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + l[i].cost * j);
          }
        }
      }
    }
    long long ans = min(dp[n - 1][0], dp[n - 1][1]);
    ans = min(dp[n - 1][2], ans);
    printf("%lld\n", ans);
  }
  return 0;
}
