#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int N = 3e5 + 7;
const int MOD = 1e9 + 7;
constexpr int mul(int a, int b) { return 1LL * a * b % MOD; }
template <typename... T>
constexpr int mul(int a, int b, T... t) {
  return mul(mul(a, b), t...);
}
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long int readl() {
  char ch = getchar();
  long long int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long int a[N], b[N];
long long int dp[N][3];
int main() {
  int T = read();
  while (T--) {
    int n = read();
    for (int i = 1; i <= n; i++) {
      a[i] = readl();
      b[i] = readl();
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 3; j++) {
        dp[i][j] = INF;
      }
    }
    dp[1][0] = 0;
    dp[1][1] = b[1];
    dp[1][2] = b[1] * 2;
    for (int i = 2; i <= n; i++) {
      for (int j = 0; j < 3; j++) {
        for (int 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] + b[i] * j);
        }
      }
    }
    cout << min(dp[n][0], min(dp[n][1], dp[n][2])) << endl;
  }
  return 0;
}
