#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17;
int d(int p1, int p2) {
  if (p1 < p2) return 3;
  return min(3, p1 - p2);
}
long long solve() {
  int n;
  cin >> n;
  vector<long long> a(n + 1), b(n + 1);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  a[n] = 1e9 + 7;
  vector<vector<long long>> dp(n + 1, vector<long long>(4, inf));
  dp[n][3] = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 4; j++) {
      if (j != 0) dp[i][j] = min(dp[i][j], dp[i + 1][d(a[i], a[i + 1])]);
      if (j != 1)
        dp[i][j] = min(dp[i][j], b[i] + dp[i + 1][d(a[i] + 1, a[i + 1])]);
      if (j != 2)
        dp[i][j] = min(dp[i][j], 2 * b[i] + dp[i + 1][d(a[i] + 2, a[i + 1])]);
    }
  }
  return dp[0][3];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t-- > 0) cout << solve() << "\n";
  return 0;
}
