#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 29;
void solve(int n) {
  vector<vector<ll>> dp(3, vector<ll>(n, -1));
  vector<ll> a(n);
  vector<ll> b(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[i] = x;
    cin >> x;
    b[i] = x;
  }
  dp[0][0] = 0;
  dp[1][0] = b[0];
  dp[2][0] = b[0] * 2;
  for (int pos = 0; pos < n; pos++) {
    for (int add = 0; add < 3; add++) {
      if (pos == 0) continue;
      ll minVal = 1e18;
      for (int i = 0; i < 3; i++) {
        if (a[pos - 1] + i != a[pos] + add) {
          minVal = min(minVal, dp[i][pos - 1]);
        }
      }
      dp[add][pos] = b[pos] * add + minVal;
    }
  }
  cout << min(min(dp[0][n - 1], dp[1][n - 1]), dp[2][n - 1]) << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int q, n;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n;
    solve(n);
  }
}
