#include <bits/stdc++.h>
using namespace std;
long long n;
int32_t main() {
  ios_base::sync_with_stdio(false);
  long long q;
  cin >> q;
  while (q--) {
    cin >> n;
    long long a[n + 1], b[n + 1];
    long long dp[n + 3][5];
    memset(dp, 0, sizeof(dp));
    for (long long i = 0; i < n; ++i) {
      cin >> a[i] >> b[i];
    }
    for (long long i = 0; i <= n; ++i)
      for (long long j = 0; j < 4; ++j) dp[i][j] = 1e15;
    dp[0][0] = 0;
    dp[0][1] = b[0];
    for (long long i = 1; i <= n; ++i) {
      for (long long j = 0; j <= 3; j++)
        for (long long k = 0; k <= 3; ++k) {
          if (a[i - 1] + j != a[i] + k) {
            dp[i][k] = min(dp[i][k], dp[i - 1][j] + k * b[i]);
          }
        }
    }
    cout << min(min(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << '\n';
  }
  return 0;
}
