#include <bits/stdc++.h>
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T lcm(T a, T b) {
  return a / __gcd(a, b) * b;
}
template <class T>
T minimize(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
T maximize(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
const long long N = 3e5 + 5;
long long a[N], cost[N];
long long dp[N][3];
long long tc;
long long n;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (cin >> tc; tc > 0; tc--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) cin >> a[i] >> cost[i];
    for (long long i = 1; i <= n; i++) {
      dp[i][0] = 1e18;
      dp[i][1] = 1e18;
      dp[i][2] = 1e18;
    }
    dp[1][0] = 0;
    dp[1][1] = cost[1];
    dp[1][2] = cost[1] * 2;
    for (long long i = 2; i <= n; i++) {
      for (__typeof(3) j = 0; j < (3); ++j) {
        for (__typeof(3) k = 0; k < (3); ++k) {
          if (a[i] + j != a[i - 1] + k) {
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + cost[i] * j);
          }
        }
      }
    }
    cout << min({dp[n][0], dp[n][1], dp[n][2]}) << '\n';
  }
  return 0;
}
