#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n], b[n];
    for (long long i = 0; i < n; i++) cin >> a[i] >> b[i];
    long long dp[n][3];
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 0;
    dp[0][1] = b[0];
    dp[0][2] = 2 * b[0];
    for (long long i = 1; i < n; i++) {
      dp[i][0] = 2e18;
      dp[i][1] = 2e18;
      dp[i][2] = 2e18;
      for (long long j = 0; j < 3; j++) {
        for (long long k = 0; k < 3; k++) {
          if (a[i] + j == a[i - 1] + k) continue;
          dp[i][j] = min(dp[i][j], dp[i - 1][k] + j * b[i]);
        }
      }
    }
    cout << min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2])) << endl;
  }
  return 0;
}
