#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 9;
vector<long long> a, b, newH;
vector<vector<long long>> dp;
long long n;
long long get(long long end, long long times) {
  if (end == 0) return b[end] * times;
  long long& ans = dp[times][end];
  if (ans != -1) return ans;
  long long temp0 = get(end - 1, 0);
  long long temp1 = get(end - 1, 1);
  long long temp2 = get(end - 1, 2);
  long long newHeight = a[end] + times;
  long long cost = b[end] * times;
  if (newHeight == a[end - 1] + 0) temp0 = 4557430888798830399ll;
  if (newHeight == a[end - 1] + 1) temp1 = 4557430888798830399ll;
  if (newHeight == a[end - 1] + 2) temp2 = 4557430888798830399ll;
  return ans = cost + min({temp0, temp1, temp2});
}
void solve() {
  cin >> n;
  a.clear();
  a.resize(n, 0);
  b.clear();
  b.resize(n, 0);
  newH.clear();
  newH.resize(n, -1);
  dp.clear();
  dp.resize(3, vector<long long>(n, -1));
  for (int i = 0, _n = (n); i < _n; i++) {
    cin >> a[i] >> b[i];
  }
  cout << min({get(n - 1, 0), get(n - 1, 1), get(n - 1, 2)}) << '\n';
  return;
}
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
