#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int n;
    cin >> n;
    vector<int> h(n), c(n);
    for (int j = 0; j < n; ++j) scanf("%d%d", &h[j], &c[j]);
    vector<vector<unsigned long long>> dp(
        n, vector<unsigned long long>(3, LLONG_MAX));
    dp[0][0] = 0;
    dp[0][1] = c[0];
    dp[0][2] = c[0] * 2;
    for (int j = 1; j < n; ++j) {
      for (int k = 0; k < 3; ++k)
        for (int s = 0; s < 3; ++s) {
          if (h[j - 1] + k != h[j] + s)
            dp[j][s] = min(dp[j][s], dp[j - 1][k] + s * c[j]);
        }
    }
    cout << min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2])) << endl;
  }
  return 0;
}
