#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
const int offset = (1 << 17);
const long long inf = (1LL << 60);
struct node {
  long long mini;
  int kamo;
  int live;
  long long prop;
  node() {
    mini = inf;
    kamo = -1;
    live = 0;
    prop = -1;
  }
};
struct tournament {
  node p[offset * 2];
  void ispis() {
    for (int i = (1); i < int(offset * 2); i++)
      cerr << "i _ p[i].live _ p[i].mini _ p[i].kamo _ p[i].prop"
           << "  " << i << " " << p[i].live << " " << p[i].mini << " "
           << p[i].kamo << " " << p[i].prop << endl;
  }
  node merge(node a, node b) {
    node ret;
    if (b.live == 0)
      ret = a;
    else if (a.live == 0)
      ret = b;
    else if (a.mini <= b.mini)
      ret = a;
    else
      ret = b;
    ret.prop = -1;
    return ret;
  }
  void init() {
    for (int i = (offset); i < int(offset * 2); i++) {
      p[i].live = 1;
      p[i].mini = inf;
      p[i].kamo = i - offset;
    }
    for (int i = offset - 1; i >= 1; i--) p[i] = merge(p[i * 2], p[i * 2 + 1]);
    for (int i = (0); i < int(offset * 2); i++) p[i].prop = -1;
  }
  void send_prop(int cvor) {
    if (p[cvor].prop == -1) return;
    for (int i = (cvor * 2); i < int(cvor * 2 + 2); i++) {
      p[i].mini = min(p[i].mini, p[cvor].prop);
      if (p[i].prop == -1) p[i].prop = p[cvor].prop;
      p[i].prop = min(p[i].prop, p[cvor].prop);
    }
    p[cvor].prop = -1;
  }
  void kill(int cvor, int l, int r, int a, int b) {
    if (l > b || r < a) return;
    if (l >= a && r <= b) {
      p[cvor].live = 0;
      return;
    }
    send_prop(cvor);
    int mid = (l + r) / 2;
    kill(cvor * 2, l, mid, a, b);
    kill(cvor * 2 + 1, mid + 1, r, a, b);
    p[cvor] = merge(p[cvor * 2], p[cvor * 2 + 1]);
  }
  void update(int cvor, int l, int r, int a, int b, long long x) {
    if (l > b || r < a) return;
    if (l >= a && r <= b) {
      p[cvor].mini = min(p[cvor].mini, x);
      if (p[cvor].prop == -1) p[cvor].prop = x;
      p[cvor].prop = min(p[cvor].prop, x);
      return;
    }
    send_prop(cvor);
    int mid = (l + r) / 2;
    update(cvor * 2, l, mid, a, b, x);
    update(cvor * 2 + 1, mid + 1, r, a, b, x);
    p[cvor] = merge(p[cvor * 2], p[cvor * 2 + 1]);
  }
  node get() { return p[1]; }
} T;
set<pair<long long, int> > s;
int moze[offset * 2];
long long dist[MAXN];
int bio[MAXN];
struct tournamentdva {
  vector<pair<long long, pair<int, int> > > v[offset * 2];
  void ubaci(int cvor, int l, int r, int a, int b,
             pair<int, pair<int, int> > x) {
    if (l > b || r < a) return;
    if (l >= a && r <= b) {
      v[cvor].push_back(x);
      return;
    }
    int mid = (l + r) / 2;
    ubaci(cvor * 2, l, mid, a, b, x);
    ubaci(cvor * 2 + 1, mid + 1, r, a, b, x);
  }
  void get(int x) {
    long long ad = dist[x];
    x += offset;
    while (x) {
      for (int i = (0); i < int((int)v[x].size()); i++) {
        if (!moze[v[x][i].first]) {
          s.insert(make_pair(v[x][i].second.first + ad, v[x][i].second.second));
          moze[v[x][i].first] = 1;
        }
      }
      v[x].clear();
      x /= 2;
    }
  }
} T2;
int n, q, S;
int t[MAXN];
int a[MAXN], b[MAXN], c[MAXN], a1[MAXN];
vector<pair<int, pair<int, int> > > v[MAXN];
void dijkstra() {
  int cvor;
  long long dst;
  s.insert(make_pair(0LL, S));
  while (1) {
    while (!s.empty() && bio[s.begin()->second]) s.erase(s.begin());
    node t = T.get();
    if ((t.live == 0 || t.mini == inf) && s.empty()) break;
    if (s.empty()) {
      cvor = t.kamo;
      dst = t.mini;
    } else if (t.live == 0 || t.mini == inf) {
      cvor = s.begin()->second;
      dst = s.begin()->first;
      s.erase(s.begin());
    } else {
      if (t.mini < s.begin()->first) {
        cvor = t.kamo;
        dst = t.mini;
      } else {
        cvor = s.begin()->second;
        dst = s.begin()->first;
        s.erase(s.begin());
      }
    }
    bio[cvor] = 1;
    dist[cvor] = dst;
    T.kill(1, 0, offset - 1, cvor, cvor);
    T2.get(cvor);
    for (int i = (0); i < int((int)v[cvor].size()); i++) {
      T.update(1, 0, offset - 1, v[cvor][i].second.first,
               v[cvor][i].second.second, dst + (long long)v[cvor][i].first);
    }
  }
}
int main() {
  scanf("%d %d %d", &n, &q, &S);
  for (int i = (0); i < int(q); i++) {
    scanf("%d", &t[i]);
    if (t[i] == 1)
      scanf("%d %d %d", &a[i], &b[i], &c[i]);
    else
      scanf("%d %d %d %d", &a[i], &b[i], &c[i], &a1[i]);
  }
  T.init();
  for (int i = (n + 1); i < int(offset); i++) T.kill(1, 0, offset - 1, i, i);
  T.kill(1, 0, offset - 1, 0, 0);
  for (int i = (0); i < int(q); i++)
    if (t[i] == 3)
      T2.ubaci(1, 0, offset - 1, b[i], c[i],
               make_pair(i, make_pair(a1[i], a[i])));
  for (int i = (0); i < int(q); i++) {
    if (t[i] == 2) v[a[i]].push_back(make_pair(a1[i], make_pair(b[i], c[i])));
    if (t[i] == 1) v[a[i]].push_back(make_pair(c[i], make_pair(b[i], b[i])));
  }
  dijkstra();
  for (int i = (1); i < int(n + 1); i++) {
    if (!bio[i])
      printf("-1 ");
    else
      printf("%lld ", dist[i]);
  }
  puts("");
  return 0;
}
