#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(17);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<long long> a(n), b(n);
    vector<vector<long long>> dp(3, vector<long long>(n));
    for (int i = 0; i < (n); i++) cin >> a[i] >> b[i];
    dp[1][0] = b[0];
    dp[2][0] = b[0] * 2;
    for (int i = 1; i < n; i++) {
      for (int d = 0; d < (3); d++) {
        dp[d][i] = 2e18;
        for (int e = 0; e < (3); e++)
          if (a[i] + d != a[i - 1] + e) dp[d][i] = min(dp[d][i], dp[e][i - 1]);
        dp[d][i] += b[i] * d;
      }
    }
    cout << min(dp[0][n - 1], min(dp[1][n - 1], dp[2][n - 1])) << "\n";
  };
  return 0;
}
