786_B. Legacy_21749
Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. 

There are n planets in their universe numbered from 1 to n. Rick is in planet number s (the earth) and he doesn't know where Morty is. As we all know, Rick owns a portal gun. With this gun he can open one-way portal from a planet he is in to any other planet (including that planet). But there are limits on this gun because he's still using its free trial.

<image>

By default he can not open any portal by this gun. There are q plans in the website that sells these guns. Every time you purchase a plan you can only use it once but you can purchase it again if you want to use it more.

Plans on the website have three types:

  1. With a plan of this type you can open a portal from planet v to planet u. 
  2. With a plan of this type you can open a portal from planet v to any planet with index in range [l, r]. 
  3. With a plan of this type you can open a portal from any planet with index in range [l, r] to planet v. 



Rick doesn't known where Morty is, but Unity is going to inform him and he wants to be prepared for when he finds and start his journey immediately. So for each planet (including earth itself) he wants to know the minimum amount of money he needs to get from earth to that planet.

Input

The first line of input contains three integers n, q and s (1 ≤ n, q ≤ 105, 1 ≤ s ≤ n) — number of planets, number of plans and index of earth respectively.

The next q lines contain the plans. Each line starts with a number t, type of that plan (1 ≤ t ≤ 3). If t = 1 then it is followed by three integers v, u and w where w is the cost of that plan (1 ≤ v, u ≤ n, 1 ≤ w ≤ 109). Otherwise it is followed by four integers v, l, r and w where w is the cost of that plan (1 ≤ v ≤ n, 1 ≤ l ≤ r ≤ n, 1 ≤ w ≤ 109).

Output

In the first and only line of output print n integers separated by spaces. i-th of them should be minimum money to get from earth to i-th planet, or  - 1 if it's impossible to get to that planet.

Examples

Input

3 5 1
2 3 2 3 17
2 3 2 2 16
2 2 2 3 3
3 3 1 1 12
1 3 3 17


Output

0 28 12 


Input

4 3 1
3 4 1 3 12
2 2 3 4 10
1 2 4 16


Output

0 -1 -1 12 

Note

In the first sample testcase, Rick can purchase 4th plan once and then 2nd plan in order to get to get to planet number 2.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 15;
const long long inf = 1e18;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int n, q, s, t, l, r, w, p, u, v, tot;
int head[maxn << 3], cnt, tra[maxn << 3], trb[maxn << 3], in[maxn], out[maxn];
struct edge {
  int to, nxt, w;
} e[maxn << 4];
inline void add(int u, int v, int _w) {
  e[++cnt].to = v;
  e[cnt].w = _w;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
void build(int l, int r, int x) {
  tra[x] = ++tot;
  trb[x] = ++tot;
  if (l == r) {
    out[l] = trb[x];
    in[l] = tra[x];
    add(trb[x], tra[x], 0);
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, x << 1);
  build(mid + 1, r, x << 1 | 1);
  add(tra[x << 1], tra[x], 0);
  add(tra[x << 1 | 1], tra[x], 0);
  add(trb[x], trb[x << 1], 0);
  add(trb[x], trb[x << 1 | 1], 0);
}
void Updata(int l, int r, int L, int R, int x, int v, int w, int op) {
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    if (op == 2)
      add(in[v], trb[x], w);
    else
      add(tra[x], out[v], w);
    return;
  }
  int mid = (l + r) >> 1;
  Updata(l, mid, L, R, x << 1, v, w, op);
  Updata(mid + 1, r, L, R, x << 1 | 1, v, w, op);
}
long long dis[maxn << 3];
struct node {
  int x;
  long long len;
  friend bool operator<(node a, node b) { return a.len > b.len; }
};
void diskstra() {
  for (int i = 0; i <= tot; ++i) dis[i] = inf;
  dis[in[s]] = dis[out[s]] = 0;
  priority_queue<node> q;
  q.push(node{in[s], 0LL});
  while (!q.empty()) {
    node now = q.top();
    q.pop();
    if (now.len > dis[now.x]) continue;
    for (int i = head[now.x]; i; i = e[i].nxt) {
      int v = e[i].to;
      if (dis[v] > dis[now.x] + e[i].w) {
        dis[v] = dis[now.x] + e[i].w;
        q.push(node{v, dis[v]});
      }
    }
  }
}
int main() {
  n = read(), q = read(), s = read();
  build(1, n, 1);
  while (q--) {
    t = read();
    if (t == 1) {
      u = read(), v = read(), w = read();
      add(in[u], out[v], w);
    } else {
      v = read(), l = read(), r = read(), w = read();
      Updata(1, n, l, r, 1, v, w, t);
    }
  }
  diskstra();
  for (int i = 1; i <= n; ++i) {
    if (dis[out[i]] == inf)
      printf("-1 ");
    else
      write(dis[out[i]]), putchar(' ');
  }
  return 0;
}
