#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)3e5 + 100;
const int INF = 0x7fffffff;
int n;
long long a[maxn], b[maxn];
long long dp[maxn][3];
void solve() {
  scanf("%d", &n);
  for (long long i = (1); i <= (n); ++i)
    for (long long j = (0); j <= (2); ++j) dp[i][j] = (long long)1e35;
  for (long long i = (1); i <= (n); ++i) scanf("%lld%lld", &a[i], &b[i]);
  dp[1][0] = 0;
  dp[1][1] = b[1];
  dp[1][2] = 2 * b[1];
  for (long long i = (2); i <= (n); ++i) {
    for (long long j = (0); j <= (2); ++j) {
      for (long long k = (0); k <= (2); ++k) {
        if (a[i - 1] + k != a[i] + j)
          dp[i][j] = min(dp[i][j], dp[i - 1][k] + b[i] * j);
      }
    }
  }
  printf("%lld\n", min({dp[n][0], dp[n][1], dp[n][2]}));
}
int main() {
  int T;
  cin >> T;
  while (T--) solve();
}
