#include <bits/stdc++.h>
using namespace std;
const int mxn = 3e5 + 10;
const long long inf = 1e18;
int q, n, ai[mxn], bi[mxn];
long long dp[mxn][3];
int main() {
  scanf("%d", &q);
  ai[0] = -100;
  while (q--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &ai[i], &bi[i]);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 3; j++) {
        dp[i][j] = inf;
      }
    }
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          if (ai[i] + j != ai[i - 1] + k) {
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + j * bi[i]);
          }
        }
      }
    }
    printf("%lld\n", min(dp[n][0], min(dp[n][1], dp[n][2])));
  }
  return 0;
}
