include bits stdc using namespace std define int long long define WL w

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define WL(t) while(t--)
#define MAXN 1000000000
#define INF 1e9
#define FOR(i,s,e) for(int i=s; i<e; i++)
#define MIN(a,b,c) min(a,min(b,c));
class fastio {
public:
fastio() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
}
} __fastio;
class var {
public:
int h = 0;
int c = 0;
};
var cost[100010];
int dp[3][100010];
int f(int p, int i) {
int &ans = dp[p][i];
if(ans != -1) return ans;
ans = INF;
FOR(k,0,3) {
if(i == 0 || cost[i].h + k != cost[i-1].h + p) {
ans = min(ans, f(k, i+1) + (k * cost[i].c));
}
}
return ans;
}
void solve() {
memset(dp,-1,sizeof(dp));
int q; cin >> q;
FOR(i,0,q) {
cin >> cost[i].h;
cin >> cost[i].c;
}
cout << f(0, 0) << endl;
}
signed main() {
__fastio;
int t; cin >> t;
WL(t) {
solve();
}
return 0;
}