#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const long long N = 3e5 + 5;
long long n, a[N], b[N], dp[N][3];
void proc() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i] >> b[i];
  dp[0][0] = 0, dp[0][1] = b[0], dp[0][2] = 2 * b[0];
  for (long long i = 1; i < n; i++)
    for (long long j = 0; j < 3; j++) {
      dp[i][j] = infll;
      for (long long lastIncrease = 0; lastIncrease < 3; lastIncrease++) {
        if (a[i - 1] + lastIncrease != a[i] + j) {
          dp[i][j] = min(dp[i][j], dp[i - 1][lastIncrease] + j * b[i]);
        }
      }
    }
  long long ans = infll;
  for (long long j = 0; j < 3; j++) ans = min(ans, dp[n - 1][j]);
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) proc();
  return 0;
}
