/**************************************************
filename :n.cpp
author :maksyuki
created time :2018/1/28 12:22:32
last modified :2018/1/28 13:00:56
file location :C:\Users\abcd\Desktop\TheEternalPoet
***************************************************/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <set>
#include <bitset>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <ios>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <complex>
#include <numeric>
#include <functional>
#include <cmath>
#include <ctime>
#include <climits>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cassert>
using namespace std;
#define CFF freopen ("in", "r", stdin)
#define CFO freopen ("out", "w", stdout)
#define CPPFF ifstream cin ("in")
#define CPPFO ofstream cout ("out")
#define DB(ccc) cout << #ccc << " = " << ccc << endl
#define DBT printf("time used: %.2lfs\n", (double) clock() / CLOCKS_PER_SEC)
#define PB push_back
#define MP(A, B) make_pair(A, B)
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef pair <int, int> PII;
typedef pair <int, bool> PIB;
const int INF = 0x7F7F7F7F;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = 2 * acos (0.0);
const int maxn = 1e5 + 6666;
int Right[maxn], Left[maxn];
void Link(int a, int b) {
Right[a] = b, Left[b] = a;
}
int main()
{
#ifdef LOCAL
CFF;
//CFO;
#endif
int n, m, id = 1;
while(cin >> n >> m) {
for(int i = 1; i <= n; i++) {
Left[i] = i - 1;
Right[i] = (i + 1) % (n + 1);
}
Left[0] = n, Right[0] = 1;
int op, vx, vy;
bool inv = false;
for(int i = 1; i <= m; i++) {
cin >> op;
if(op == 4) {
inv = !inv; continue;
}
cin >> vx >> vy;
if(op == 3 && Right[vy] == vx) swap(vx, vy);
if(op < 3 && inv) op = 3 - op;
if(op == 1 && vx == Left[vy]) continue;
if(op == 2 && vx == Right[vy]) continue;
int lx = Left[vx], rx = Right[vx], ly = Left[vy], ry = Right[vy];
if(op == 1)
Link(lx, rx), Link(ly, vx), Link(vx, vy);
else if(op == 2)
Link(lx, rx), Link(vy, vx), Link(vx, ry);
else if(op == 3) {
if(Right[vx] == vy)
Link(lx, vy), Link(vy, vx), Link(vx, ry);
else
Link(lx, vy), Link(vy, rx), Link(ly, vx), Link(vx, ry);
}
}
int p = 0;
LL ans = 0;
for(int i = 1; i <= n; i++) {
p = Right[p];
if(i % 2) ans += p;
}
if(inv && !(n % 2)) ans = ((LL) n * (n + 1) / 2) - ans;
cout << "Case " << id++ << ": " << ans << endl;
}
return 0;
}