#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
struct fast_ios {
  fast_ios() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
  }
} fast_ios_;
int q, n, pa, push_back, a, b;
ll pd[3], dp[3], an;
int main() {
  cin >> q;
  while (q--) {
    cin >> n >> pa >> push_back;
    pd[0] = 0;
    pd[1] = push_back;
    pd[2] = 2 * push_back;
    for (int i = 1; i < n; ++i) {
      dp[0] = dp[1] = dp[2] = 1e15;
      cin >> a >> b;
      for (int j = 0; j < 3; ++j) {
        for (int k = 0; k < 3; ++k) {
          if (a + j != pa + k) {
            dp[j] = min(dp[j], pd[k] + j * b);
          }
        }
      }
      pd[0] = dp[0];
      pd[1] = dp[1];
      pd[2] = dp[2];
      pa = a;
      push_back = b;
    }
    ll an = min({pd[0], pd[1], pd[2]});
    cout << an << '\n';
  }
  return 0;
}
