#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int a[maxn], b[maxn];
long long dp[maxn][3];
int main() {
  int t;
  scanf("%d", &t);
  a[0] = -1e7;
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &a[i], &b[i]);
      dp[i][0] = dp[i][1] = dp[i][2] = 1e18;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= 2; j++)
        for (int k = 0; k <= 2; k++)
          if (a[i] + j != a[i - 1] + k)
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + 1LL * j * b[i]);
    }
    cout << min(dp[n][0], min(dp[n][1], dp[n][2])) << endl;
  }
}
