#include <bits/stdc++.h>
using namespace std;
const int sizee = 3e5 + 99;
int N[sizee];
int cost[sizee];
int n;
long long dp[sizee][4];
const long long INF64 = (long long)(1e18) + 100;
long long solve(int pos, int prev_add) {
  long long &ret = dp[pos][prev_add];
  if (ret != -1) return ret;
  if (pos == n) return ret = 0;
  ret = INF64;
  for (long long i = 0; i <= 2; i++) {
    if (pos == 0 || N[pos] + i != N[pos - 1] + prev_add) {
      ret = min(ret, solve(pos + 1, i) + i * cost[pos]);
    }
  }
  return ret;
}
int main() {
  ios::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 0; i <= n; i++) {
      dp[i][0] = dp[i][1] = dp[i][2] = -1;
    }
    for (int i = 0; i < n; i++) {
      cin >> N[i] >> cost[i];
    }
    cout << solve(0, 0) << '\n';
  }
  return 0;
}
