#include <bits/stdc++.h>
using namespace std;
template <class T>
void re(T& x) {
  cin >> x;
}
template <class T1, class T2>
void re(pair<T1, T2>& x) {
  re(x.first);
  re(x.second);
}
template <class T>
void re(vector<T>& x) {
  for (long i = 0; i < x.size(); i++) {
    re(x[i]);
  }
}
template <class T>
void re(deque<T>& x) {
  for (long i = 0; i < x.size(); i++) {
    re(x[i]);
  }
}
template <class T1, class T2>
pair<T1, T2> mp(T1& x, T2& z) {
  return make_pair(x, z);
}
long long n;
vector<long long> dp[3];
vector<bool> ok[3];
vector<pair<long long, long long> > v;
long long solve(long long x, long z) {
  if (x == 0) {
    return z * v[x].second;
  }
  if (ok[z][x]) {
    return dp[z][x];
  }
  long long ret = 1e18;
  for (long i = 0; i < 3; i++) {
    if (v[x - 1].first + i != v[x].first + z) {
      ret = min(ret, solve(x - 1, i));
    }
  }
  ret += z * v[x].second;
  ok[z][x] = true;
  dp[z][x] = ret;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long t;
  cin >> t;
  for (long i = 0; i < t; i++) {
    cin >> n;
    for (long j = 0; j < 3; j++) {
      dp[j].clear();
      dp[j].resize(n);
      ok[j].clear();
      ok[j].resize(n);
    }
    v.clear();
    v.resize(n);
    re(v);
    long long ans = solve(n - 1, 0);
    ans = min(ans, solve(n - 1, 1));
    ans = min(ans, solve(n - 1, 2));
    cout << ans << endl;
  }
  return 0;
}
