#include <bits/stdc++.h>
using namespace std;
const int M = 3e5 + 5;
int n;
long long a[M], b[M], dp[M][5];
long long solve(int ind, long long prev) {
  if (ind == n) return 0;
  if (dp[ind][prev] != -1) return dp[ind][prev];
  long long ans = 0x3f3f3f3f3f3f3f3f;
  for (long long i = 0; i < 3; i++) {
    if (a[ind] + i != a[ind - 1] + prev)
      ans = min(ans, solve(ind + 1, i) + (b[ind] * i));
  }
  return dp[ind][prev] = ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  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 >> a[i] >> b[i];
    }
    cout << min(solve(1, 0), min(solve(1, 1) + b[0], solve(1, 2) + b[0] + b[0]))
         << '\n';
  }
  return 0;
}
