#include <bits/stdc++.h>
using namespace std;
template <typename T>
T MAX(T a, T b) {
  return (a > b) ? a : b;
}
template <typename T>
T MIN(T a, T b) {
  return (a < b) ? a : b;
}
template <typename T>
void UMAX(T &a, T b) {
  a = (a > b ? a : b);
}
template <typename T>
void UMIN(T &a, T b) {
  a = (a < b ? a : b);
}
int readint() {
  char c = getchar();
  int ret = 0;
  while (!(c >= '0' && c <= '9')) c = getchar();
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret;
}
void putint(int v) {
  if (!v) {
    putchar('0');
    return;
  }
  if (v >= 10) putint(v / 10);
  putchar('0' + (v % 10));
}
int n, a[300005], b[300005];
long long dp[300005][3];
void solve() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%d%d", a + i, b + i);
  dp[0][0] = 0ll;
  dp[0][1] = (long long)b[0];
  dp[0][2] = 2ll * (long long)b[0];
  for (i = 1; i < n; ++i) {
    for (j = 0; j < 3; ++j) {
      long long mn = (long long)1e18;
      for (k = 0; k < 3; ++k) {
        if (a[i - 1] + k != a[i] + j) {
          UMIN(mn, dp[i - 1][k] + (long long)j * (long long)b[i]);
        }
      }
      dp[i][j] = mn;
    }
  }
  printf("%I64d\n", MIN(dp[n - 1][0], MIN(dp[n - 1][1], dp[n - 1][2])));
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
