#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int q;
  cin >> q;
  while (q--) {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<vector<long long> > dp(n, vector<long long>(3, 1000000000000000001));
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    dp[0][0] = 0, dp[0][1] = b[0], dp[0][2] = 2 * b[0];
    for (int i = 1; i < n; i++)
      for (int j = 0; j < 3; j++)
        for (int k = 0; k < 3; k++)
          if (a[i] + j != a[i - 1] + k)
            dp[i][j] = min(dp[i][j], dp[i - 1][k] + j * b[i]);
    cout << min(dp[n - 1][0], min(dp[n - 1][1], dp[n - 1][2])) << "\n";
  }
  return 0;
}
