#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 11;
const long long M = 1e3 + 10;
const long long big = 1e16;
const long long hsh2 = 1964325029;
const long long mod = 1e9 + 7;
const long double EPS = 1e-8;
const long long block = 1e7;
const long long shift = 2e3;
long long n, q, second;
struct que {
  long long r, w;
};
vector<que> Q[4 * N];
vector<pair<pair<long long, int>, que>> O;
struct seg {
  long long t[4 * N];
  int p[4 * N];
  long long u[4 * N];
  void push(long long v, long long tl, long long tr) {
    t[v] = min(t[v], u[v]);
    if (tl != tr)
      u[v * 2] = min(u[v], u[v * 2]), u[v * 2 + 1] = min(u[v], u[v * 2 + 1]);
  }
  void mrg(long long v, long long tl, long long tr) {
    if (t[v * 2] == -1 || t[v * 2 + 1] == -1) {
      if (t[v * 2] == -1)
        t[v] = t[v * 2 + 1], p[v] = p[v * 2 + 1];
      else
        t[v] = t[v * 2], p[v] = p[v * 2];
    } else {
      if (t[v * 2] < t[v * 2 + 1])
        t[v] = t[v * 2], p[v] = p[v * 2];
      else
        t[v] = t[v * 2 + 1], p[v] = p[v * 2 + 1];
    }
  }
  void upd(long long l, long long r, long long x, long long v = 1,
           long long tl = 1, long long tr = n) {
    push(v, tl, tr);
    if (l > tr || tl > r) return;
    if (x == -1) {
      for (auto u : Q[v]) {
        O.push_back(make_pair(make_pair(tl, tr), u));
      }
      Q[v].clear();
    }
    if (l <= tl && tr <= r) {
      u[v] = min(u[v], x);
      push(v, tl, tr);
      return;
    }
    long long m = tl + tr >> 1;
    upd(l, r, x, v * 2, tl, m);
    upd(l, r, x, v * 2 + 1, m + 1, tr);
    mrg(v, tl, tr);
  }
  pair<long long, int> subj(pair<long long, int> z1, pair<long long, int> z2) {
    if (z1.second == -1) return z2;
    if (z2.second == -1) return z1;
    if (z1.first == -1 || z2.first == -1) return max(z1, z2);
    return min(z1, z2);
  }
  pair<long long, int> get(long long l, long long r, long long v = 1,
                           long long tl = 1, long long tr = n) {
    push(v, tl, tr);
    if (l > tr || tl > r) return make_pair(big, -1);
    if (l <= tl && tr <= r) return make_pair(t[v], p[v]);
    long long m = (tl + tr) >> 1;
    return subj(get(l, r, v * 2, tl, m), get(l, r, v * 2 + 1, m + 1, tr));
  }
} rt[2];
void build(long long v = 1, long long l = 1, long long r = n) {
  if (l == r) {
    for (int j = 0; j < 2; j++) rt[j].t[v] = rt[j].u[v] = big, rt[j].p[v] = l;
    return;
  }
  long long m = l + r >> 1;
  build(v * 2, l, m);
  build(v * 2 + 1, m + 1, r);
  for (int j = 0; j < 2; j++) rt[j].t[v] = rt[j].u[v] = big, rt[j].p[v] = l;
}
void fll(long long l, long long r, que x, long long v = 1, long long tl = 1,
         long long tr = n) {
  if (l > tr || tl > r) return;
  if (l <= tl && tr <= r) {
    Q[v].push_back(x);
    return;
  }
  long long m = tl + tr >> 1;
  fll(l, r, x, v * 2, tl, m);
  fll(l, r, x, v * 2 + 1, m + 1, tr);
}
vector<pair<long long, int>> gr[N];
vector<pair<int, pair<long long, int>>> gr2[N];
long long ans[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q >> second;
  while (q--) {
    int t, v, l, r, z;
    cin >> t;
    if (t == 1) {
      cin >> l >> r >> z;
      gr[l].push_back(make_pair(r, z));
    }
    if (t == 2) {
      cin >> v >> l >> r >> z;
      gr2[v].push_back(make_pair(z, make_pair(l, r)));
    }
    if (t == 3) {
      cin >> v >> l >> r >> z;
      que first;
      first.r = v, first.w = z;
      fll(l, r, first);
    }
  }
  build();
  rt[0].upd(second, second, 0);
  rt[1].upd(second, second, 0);
  long long cnt = n;
  while (cnt--) {
    pair<long long, int> p = rt[0].get(1, n);
    ans[p.second] = p.first;
    rt[0].upd(p.second, p.second, -1);
    if (p.first == big) continue;
    for (auto u : O) {
      rt[0].upd(u.second.r, u.second.r, p.first + u.second.w);
      rt[1].upd(u.second.r, u.second.r, p.first + u.second.w);
    }
    O.clear();
    for (auto u : gr[p.second]) {
      rt[1].upd(u.first, u.first, p.first + u.second);
      rt[0].upd(u.first, u.first, p.first + u.second);
    }
    for (auto u : gr2[p.second]) {
      rt[1].upd(u.second.first, u.second.second, p.first + u.first);
      rt[0].upd(u.second.first, u.second.second, p.first + u.first);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (ans[i] == big) ans[i] = -1;
    cout << ans[i] << " ";
  }
}
