#include <bits/stdc++.h>
using namespace std;
int t;
int n;
long long dp[300100][6], b[300100];
int a[300100];
int get(int x, int y) {
  if (x == y) return 1;
  if (x < y) return 0;
  if (x - y <= 2) return x - y + 1;
  return 4;
}
long long Solve(int i, int j) {
  if (i == n) return 0;
  long long &ret = dp[i][j];
  if (ret + 1) return ret;
  ret = 2e18;
  if (j == 0 || j == 4) {
    for (long long k = 0; k <= 2; k++)
      ret = min(ret, k * b[i] + Solve(i + 1, get(a[i] + k, a[i + 1])));
  } else if (j == 1) {
    for (long long k = 1; k <= 2; k++)
      ret = min(ret, k * b[i] + Solve(i + 1, get(a[i] + k, a[i + 1])));
  } else if (j == 2 || j == 3) {
    j--;
    for (long long k = 0; k <= 2; k++) {
      if (k == j) continue;
      ret = min(ret, k * b[i] + Solve(i + 1, get(a[i] + k, a[i + 1])));
    }
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    a[n] = -1e9;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 5; j++) dp[i][j] = -1;
    cout << Solve(0, 0) << endl;
  }
  return 0;
}
