#include <bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
const double pi = acos(-1.0);
const double eps = 1e-9;
typedef long long LL;
const int N = 1e6 + 10;
const int M = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double f = 2.32349;
LL dp[N][4], a[N], b[N];
LL min3(LL a, LL b, LL c) { return min(min(a, b), c); }
void solve() {
IOS;
int t, n;
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
dp[i][0] = dp[i][1] = dp[i][2] = 0;
}
for (int i = 1; i <= n; i++) {
if (a[i - 1] == a[i]) {
dp[i][0] = min(dp[i - 1][1], dp[i - 1][2]);
dp[i][1] = min(dp[i - 1][0], dp[i - 1][2]) + b[i];
dp[i][2] = min(dp[i - 1][0], dp[i - 1][1]) + 2 * b[i];
} else if (a[i - 1] + 1 == a[i]) {
dp[i][0] = min(dp[i - 1][0], dp[i - 1][2]);
dp[i][1] = min(dp[i - 1][1], dp[i - 1][0]) + b[i];
dp[i][2] = min3(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 2 * b[i];
} else if (a[i - 1] - 1 == a[i]) {
dp[i][0] = min3(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]);
dp[i][1] = min(dp[i - 1][1], dp[i - 1][2]) + b[i];
dp[i][2] = min(dp[i - 1][0], dp[i - 1][2]) + 2 * b[i];
} else if (a[i - 1] + 2 == a[i]) {
dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = min3(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + b[i];
dp[i][2] = min3(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + 2 * b[i];
} else {
dp[i][0] = min3(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]);
dp[i][1] = min3(dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]) + b[i];
dp[i][2] = min(dp[i - 1][1], dp[i - 1][2]) + 2 * b[i];
}
}
cout << min3(dp[n][0], dp[n][1], dp[n][2]) << endl;
}
}
signed main() {
solve();
return 0;
}