#include <bits/stdc++.h>
using namespace std;
long long len[300009];
long long price[300009];
long long dp[300009][3];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q, n;
  cin >> q;
  for (int t = 0; t < q; t++) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> len[i];
      cin >> price[i];
    }
    dp[0][0] = 0LL;
    dp[0][1] = price[0];
    dp[0][2] = price[0] + price[0];
    for (int i = 1; i < n; i++) {
      for (long long h = 0; h < 3; h++) {
        long long best = 1000000000000000009;
        for (int prev = 0; prev < 3; prev++) {
          if (len[i - 1] + prev != len[i] + h) {
            best = min(best, dp[i - 1][prev]);
          }
        }
        dp[i][h] = h * price[i] + best;
      }
    }
    cout << min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2])) << "\n";
  }
}
