#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, q;
long long a[N], dp[N][3], b[N];
int main() {
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &n);
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    a[0] = -3;
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%lld%lld", &a[i], &b[i]);
      if (a[i] == a[i - 1]) {
        dp[i][0] = min(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) + 2 * b[i];
      } else if (a[i] == a[i - 1] + 1) {
        dp[i][0] = min(dp[i - 1][0], dp[i - 1][2]);
        dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + b[i];
        dp[i][2] =
            min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]) + 2 * b[i];
      } else if (a[i] == a[i - 1] + 2) {
        dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]) + b[i];
        dp[i][2] =
            min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]) + 2 * b[i];
      } else if (a[i] == a[i - 1] - 1) {
        dp[i][0] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]);
        dp[i][1] = min(dp[i - 1][1], dp[i - 1][2]) + b[i];
        dp[i][2] = min(dp[i - 1][0], dp[i - 1][2]) + 2 * b[i];
      } else if (a[i] == a[i - 1] - 2) {
        dp[i][0] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]);
        dp[i][1] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]) + b[i];
        dp[i][2] = min(dp[i - 1][1], dp[i - 1][2]) + 2 * b[i];
      } else {
        dp[i][0] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]);
        dp[i][1] = min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]) + b[i];
        dp[i][2] =
            min(min(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][2]) + 2 * b[i];
      }
    }
    printf("%lld\n", min(min(dp[n][0], dp[n][1]), dp[n][2]));
  }
  return 0;
}
