#include <bits/stdc++.h>
using namespace std;
vector<int> a(300010), b(300010);
unsigned long long int dp[3][300010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
    }
    unsigned long long int s;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
        if (i == 0) {
          dp[j][i] = (1ULL * b[i] * j);
        } else {
          s = (unsigned long long int)1e18 + 10;
          for (int prev = 0; prev < 3; prev++) {
            if (a[i - 1] + prev == a[i] + j) continue;
            s = min(s, dp[prev][i - 1]);
          }
          dp[j][i] = s + (1ULL * j * b[i]);
        }
      }
    }
    s = (unsigned long long int)1e18 + 10;
    for (int i = 0; i < 3; i++) {
      s = min(s, dp[i][n - 1]);
    }
    cout << s << "\n";
  }
  return 0;
}
