#include <bits/stdc++.h>
using namespace std;
void FLASH() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void SETF() { cout.ios_base::setf(ios_base::fixed); }
void UNSETF() { cout.ios_base::unsetf(ios_base::fixed); }
int ar[300001];
long long arr[300001], brr[300001];
long long memo[300001][3];
int vis[300001][3];
int n;
long long BALLIA(int id, int mi, int T) {
  if (id == n) return 0;
  if (vis[id][mi] == T) return memo[id][mi];
  long long ans = 1000000000000000001;
  if (!id || (arr[id - 1] + mi != arr[id]))
    ans = min(ans, BALLIA(id + 1, 0, T));
  if (!id || (arr[id - 1] + mi != arr[id] + 1))
    ans = min(ans, brr[id] + BALLIA(id + 1, 1, T));
  if (!id || (arr[id - 1] + mi != arr[id] + 2))
    ans = min(ans, 2 * brr[id] + BALLIA(id + 1, 2, T));
  memo[id][mi] = ans;
  vis[id][mi] = T;
  return ans;
}
void solve(int T) {
  std::cin >> n;
  for (int i = 0; i < n; i++) std::cin >> arr[i] >> brr[i];
  long long ans = BALLIA(0, 0, T);
  std::cout << ans << "\n";
  return;
}
int main(void) {
  FLASH();
  for (int i = 0; i < 300001; i++) {
    for (int j = 0; j < 3; j++) {
      vis[i][j] = 300001;
      memo[i][j] = 0;
    }
  }
  int T;
  cin >> T;
  while (T--) solve(T);
  return 0;
}
