#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18 + 50;
long long int a[400000];
long long int b[400000];
long long int dp[400000][3];
void init(int N) {
  for (int i = 0; i <= N; i++) {
    dp[i][0] = dp[i][1] = dp[i][2] = -1;
  }
}
long long int n;
long long int f(long long int pos, long long int e) {
  if (pos == n) {
    return 0;
  }
  if (dp[pos][e] != -1) {
    return dp[pos][e];
  }
  dp[pos][e] = INF;
  if (pos == 0) {
    dp[pos][e] = min(
        {f(pos + 1, 0), f(pos + 1, 1) + b[pos], f(pos + 1, 2) + 2 * b[pos]});
  } else {
    if (a[pos - 1] + e != a[pos]) dp[pos][e] = f(pos + 1, 0);
    if (a[pos - 1] + e != a[pos] + 1)
      dp[pos][e] = min(dp[pos][e], f(pos + 1, 1) + b[pos]);
    if (a[pos - 1] + e != a[pos] + 2)
      dp[pos][e] = min(dp[pos][e], f(pos + 1, 2) + 2 * b[pos]);
  }
  return dp[pos][e];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    init(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    cout << f(0ll, 0ll) << endl;
  }
  return 0;
}
