Problem: Vasya likes to travel by train, but doesn't like when the car he travels in is located in the tail of the train.

Vasya gets on the train at the station. The train consists of n cars indexed from 1 to n counting from the locomotive (head of the train). Three types of events occur while the train is moving:

  1. Some number of cars are added to the head of the train; 
  2. Some number of cars are added to the tail of the train; 
  3. Vasya recalculates the values of the convenience of the cars (read more about it below). 



At each moment of time we will index the cars from the head of the train, starting from 1. Note that when adding new cars to the head of the train, the indexing of the old ones may shift.

To choose which car to go in, Vasya will use the value A_i for each car (where i is a car index), which is calculated as follows:

  * At the beginning of the trip A_i=0, as well as for the new cars at the time of their addition. 
  * During the next recalculation Vasya chooses some positive integers b and s and adds to all A_i value b + (i - 1) ⋅ s. 



Vasya hasn't decided yet where he will get on the train and where will get off the train, so after each event of one of the three types he wants to know the least index of the car, such that its value A_i is minimal. Since there is a lot of cars, Vasya asked you to write a program that answers his question.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^9, 1 ≤ m ≤ 300 000), the number of cars in the train at the time of departure from the station and the number of stations, respectively.

Next m lines contain the descriptions of events. Each event is one of the following three types:

  * "1 k" (1 ≤ k ≤ 10^9), add k cars to the head of the train 
  * "2 k" (1 ≤ k ≤ 10^9), add k cars to the tail of the train 
  * "3 b s" (1 ≤ b, s ≤ 10^9), recalculate the convenience of all train cars. 



It is guaranteed that at any time the train length does not exceed 10^9. Also it's guaranteed that the integers A_i will not grow too high. Formally, it's guaranteed that if we sum the largest addition over all events of the 3-rd type (that is, b + (n - 1) ⋅ s, where n is the number of cars at that moment) then the acquired sum would be at most 10^{18}.

Output

After each of the m queries print two integers: j and A_j — the number of the car closest to the head of the train, such that its value A_j is minimal, and the value A_j itself.

Example

Input


1 8
1 1
3 1 1
3 1 1
2 1
2 1
3 1 1
2 1
3 1 5


Output


1 0
1 1
1 2
3 0
3 0
1 3
5 0
1 4

Note

  * Initially the train consists of one car with A_1 = 0, let's denote train as [0] for simplicity.
  * After adding one car to the head, train is [0, 0].
  * After recalculation of values with parameters b=1, s=1, train is [1, 2].
  * After another recalculation of values with the parameters b=1, s=1, train is [2, 4].
  * After adding one car to the end, train is [2, 4, 0].
  * After another adding one car to the end, train is [2, 4, 0, 0].
  * After recalculation of values with parameters b=1, s=1, train is [3, 6, 3, 4].
  * After adding one car to the end, train is [3, 6, 3, 4, 0].
  * After recalculation of values with parameters b=1, s=5, train is [4, 12, 14, 20, 21].

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 3e5 + 50;
const int mod = 1e9 + 7;
int a[maxn];
long long pre[maxn], lg[maxn << 2];
long long la[maxn << 2], lb[maxn << 2];
void build(int rt, int l, int r) {
  if (l == r)
    lg[rt] = a[l];
  else {
    int mid = (l + r) >> 1;
    build((rt << 1), l, mid);
    build((rt << 1 | 1), mid + 1, r);
    lg[rt] = lg[(rt << 1)] + lg[(rt << 1 | 1)];
  }
}
inline void down(int rt) {
  lb[(rt << 1)] += lb[rt];
  lb[(rt << 1 | 1)] += lb[rt];
  la[(rt << 1)] += la[rt];
  la[(rt << 1 | 1)] += la[rt] + lg[(rt << 1)] * lb[rt];
  la[rt] = lb[rt] = 0;
}
inline void update(int rt, int l, int r, int L, int R, long long b, int s) {
  if (L <= l and r <= R) {
    la[rt] += b;
    lb[rt] += s;
  } else {
    if (la[rt] or lb[rt]) down(rt);
    int mid = (l + r) >> 1;
    if (L <= mid and R > mid) {
      update((rt << 1), l, mid, L, mid, b, s);
      update((rt << 1 | 1), mid + 1, r, mid + 1, R,
             b + (pre[(mid)] - pre[(L - 1)]) * s, s);
    } else if (L <= mid) {
      update((rt << 1), l, mid, L, R, b, s);
    } else {
      update((rt << 1 | 1), mid + 1, r, L, R, b, s);
    }
  }
}
inline long long query(int rt, int l, int r, int pos) {
  if (l == r)
    return la[rt];
  else {
    if (la[rt] or lb[rt]) down(rt);
    int mid = (l + r) >> 1;
    if (pos <= mid) return query((rt << 1), l, mid, pos);
    return query((rt << 1 | 1), mid + 1, r, pos);
  }
}
int od[maxn], b[maxn], s[maxn];
deque<int> qu;
int le[maxn], ri[maxn];
inline int fl(int k) { return le[k] ? le[k] = fl(le[k]) : k; }
inline int fr(int k) { return ri[k] ? ri[k] = fr(ri[k]) : k; }
set<pair<long long, int> > use;
long long add;
pair<long long, int> my[maxn];
inline void check_merge(int r, int s, int cc) {
  if (use.empty()) {
    add -= s;
    return;
  }
  while (!use.empty()) {
    pair<long long, int> f = *use.begin();
    if (f.first + add > s) break;
    use.erase(use.begin());
    int pos = f.second;
    le[pos] = pos - 1;
    ri[pos - 1] = pos;
    int g = fr(pos);
    if (g != r) {
      ++g;
      use.erase(my[g]);
      int an = fl(g - 1);
      long long a = query(1, 1, cc, an), b = query(1, 1, cc, g),
                len = (pre[(g - 1)] - pre[(an - 1)]);
      my[g].first = (a - b + len - 1) / len - add;
      use.insert(my[g]);
    }
  }
  add -= s;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  qu.push_back(n);
  int pos = 1;
  for (int i = 1; i <= m; ++i) {
    cin >> od[i];
    if (od[i] == 1) {
      int len;
      cin >> len;
      qu.push_front(len);
      ++pos;
    } else if (od[i] == 2) {
      int len;
      cin >> len;
      qu.push_back(len);
    } else {
      cin >> b[i] >> s[i];
    }
  }
  int cc = 0;
  for (int i = 1; !qu.empty(); ++i) {
    a[i] = qu.front();
    qu.pop_front();
    cc = i;
  }
  for (int i = 1; i <= cc; ++i) pre[i] = pre[i - 1] + a[i];
  build(1, 1, cc);
  int ul = pos, ur = pos;
  for (int i = 1; i <= m; ++i) {
    if (od[i] == 1) {
      le[ul] = ul - 1;
      ri[ul - 1] = ul;
      --ul;
      for (auto it = use.begin(); it != use.end(); ++it) {
        int pos = it->second;
        le[pos] = pos - 1;
        ri[pos - 1] = pos;
      }
      use.clear();
    } else if (od[i] == 2) {
      ++ur;
      my[ur].second = ur;
      long long val = query(1, 1, cc, fl(ur - 1));
      if (val == 0) {
        le[ur] = ur - 1;
        ri[ur - 1] = ur;
      } else {
        int r = ur;
        int an = fl(r - 1);
        long long a = query(1, 1, cc, an), b = query(1, 1, cc, r),
                  len = (pre[(r - 1)] - pre[(an - 1)]);
        my[r].first = (a - b + len - 1) / len - add;
        use.insert(my[r]);
      }
    } else {
      check_merge(ur, s[i], cc);
      update(1, 1, cc, ul, ur, b[i], s[i]);
    }
    int p = fl(ur);
    cout << (pre[(p - 1)] - pre[(ul - 1)]) + 1 << " " << query(1, 1, cc, p)
         << "\n";
  }
  return 0;
}