#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long N = 3e5 + 5;
const long long mod = 1000000007;
long long n;
long long a[N], b[N];
long long dp[N][3];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      cin >> 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++) {
      dp[i][0] = dp[i][1] = dp[i][2] = INF;
      for (long long j = 0; j <= 2; j++) {
        for (long long p = 0; p <= 2; p++) {
          if (a[i] + j == a[i - 1] + p) continue;
          dp[i][j] = min(dp[i][j], dp[i - 1][p] + b[i] * j);
        }
      }
    }
    long long ans = min({dp[n][0], dp[n][1], dp[n][2]});
    cout << ans << endl;
  }
  return 0;
}
