#include <bits/stdc++.h>
using namespace std;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) {
  return (b == 0LL ? a : gcd(b, a % b));
}
inline long long mod(long long a, long long b) { return ((a % b) + b) % b; }
inline long long expo(long long b, long long p, long long m = MOD) {
  long long ans = 1;
  while (p > 0) {
    if (p & 1LL) ans = mod(ans * b, m);
    b = mod(b * b, m);
    p >>= 1LL;
  }
  return ans;
}
const int N = 3e5 + 5;
long long dp[N][5], v[N], p[N];
int n;
inline int pega(int a, int b) { return a == b ? 1 : a - 1 == b ? 2 : 0; }
long long solve(int i, int ant) {
  if (i == n) return (ant == 1 ? p[i] : 0);
  long long& ans = dp[i][ant];
  if (ans != -1) return ans;
  long long zero = solve(i + 1, pega(v[i], v[i + 1]));
  long long um = solve(i + 1, pega(v[i] + 1, v[i + 1])) + p[i];
  long long dois = solve(i + 1, pega(v[i] + 2, v[i + 1])) + 2LL * p[i];
  if (ant == 0) return ans = min({zero, um, dois});
  if (ant == 1) return ans = min(um, dois);
  return ans = min(zero, dois);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int _;
  cin >> _;
  while (_--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> v[i] >> p[i];
      dp[i][0] = dp[i][1] = dp[i][2] = -1;
    }
    cout << solve(1, 0) << '\n';
  }
  return 0;
}
