#include <bits/stdc++.h>
using namespace std;
const int N = (int)3e5 + 99;
const long long INF = (long long)1e18 + 100;
int a[N];
int b[N];
long long dp[N][3];
int n;
long long calc(long long add, long long pos) {
  long long &res = dp[pos][add];
  if (res != -1) return res;
  res = INF;
  if (pos == n) return res = 0;
  for (long long x = 0; x <= 2; x++) {
    if (pos == 0 || a[pos] + x != a[pos - 1] + add)
      res = min(res, calc(x, pos + 1) + x * (b[pos]));
  }
  return res;
}
void Solve() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  for (int i = 0; i <= n; i++) dp[i][0] = dp[i][1] = dp[i][2] = -1;
  cout << calc(0, 0) << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    Solve();
  }
  return 0;
}
