#include <bits/stdc++.h>
using namespace std;
long long t, n, h[300010], r[300010], dp[300010][3];
int main() {
  scanf("%lld", &t);
  while (t--) {
    cin >> n;
    for (long long i = (1); i < (n + 1); i++) scanf("%lld%lld", &h[i], &r[i]);
    for (long long i = (1); i < (n + 1); i++) {
      for (long long j = (0); j < (3); j++) {
        dp[i][j] = 1e18;
        for (long long k = (0); k < (3); k++) {
          if (h[i] + j != h[i - 1] + k)
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + j * r[i]);
        }
      }
    }
    cout << min(dp[n][0], min(dp[n][1], dp[n][2])) << '\n';
  }
  return 0;
}
