#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 5;
long long inf = 1e18 + 5;
int n;
long long a[maxn], b[maxn];
long long dp[maxn][3];
long long min(long long a, long long b) { return a > b ? b : a; }
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &n);
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j < 3; j++) dp[i][j] = inf;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%lld %lld", a + i, b + i);
    }
    dp[0][0] = 0ll;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          if (a[i] + j != a[i - 1] + k)
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + j * b[i]);
        }
      }
    }
    printf("%lld\n", min(min(dp[n][0], dp[n][1]), dp[n][2]));
  }
  return 0;
}
