import java.io.*;
import java.util.*;
import java.math.*;
import static java.
lang.
Math.
*; import static java.
util.
Arrays.
*;
class A {
static final char PROB = A.class.getSimpleName().charAt(0);
static final boolean PRAC = false;
static final int INF = 1 << 20;
static final int[] di = { -1, 0, 0, 1 };
static final int[] dj = { 0, -1, 1, 0 };
static Scanner sc
= new Scanner
(System.
in);
final int N;
final char[] R;
final int[] P;
public A() {
N = sc.nextInt();
R = new char[N];
P = new int[N];
for(int i = 0; i < N; i++) {
R[i] = sc.next().charAt(0);
P[i] = sc.nextInt();
}
}
int ans = 0;
for(int i = 0, ot = 0, bt = 0, op = 1, bp = 1; i < N; i++)
switch(R[i]) {
case 'O' :
ans = ot = max(ot + abs(P[i] - op), bt) + 1;
op = P[i];
break;
case 'B' :
ans = bt = max(bt + abs(P[i] - bp), ot) + 1;
bp = P[i];
break;
}
return "" + ans;
}
public static void main
(String...
args) { //large();
int T
= Integer.
parseInt(sc.
nextLine()); for (int t = 1; t <= T; t++) {
System.
err.
printf("Case #%s%n", t
); System.
out.
printf("Case #%s: %s%n", t,
new A
().
solve()); }
}
public static void small() {
String in
= PROB
+ "-small" + (PRAC
? "-practice" : "-attempt" + 0) + ".in"; String out
= PROB
+ "-small.out"; try {
if (!PRAC)
for (int i
= 1; new File(PROB
+ "-small" + "-attempt" + i
+ ".in").
exists(); i
++) in = PROB + "-small" + "-attempt" + i + ".in";
e.printStackTrace();
}
}
public static void large() {
String in
= PROB
+ "-large" + (PRAC
? "-practice" : "") + ".in"; String out
= PROB
+ "-large.out"; try {
e.printStackTrace();
}
}
private static void debug
(Object...
os) { System.
err.
println(deepToString
(os
)); }
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5tYXRoLio7CgppbXBvcnQgc3RhdGljIGphdmEubGFuZy5NYXRoLio7CmltcG9ydCBzdGF0aWMgamF2YS5sYW5nLkNoYXJhY3Rlci4qOwppbXBvcnQgc3RhdGljIGphdmEudXRpbC5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