#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main () {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int,int>>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    g[a].emplace_back(b, c);
  }
  for (int start = 0; start < n; start++) {
    vector<int> dist(n, 1 << 30);
    priority_queue<pair<int, int>> que;
    que.emplace(0, start);
    int ans = -1;
    bool flag = false;
    while (!que.empty()) {
      auto [curd, cur] = que.top();
      que.pop();
      curd = -curd;
      if (cur == start) {
        if (flag) {
          ans = curd;
          break;
        }
        flag = true;
      }
      if (dist[cur] < curd) continue;
      for (auto [nbr, d] : g[cur]) {
        int nd = curd + d;
        if (dist[nbr] > nd) {
          if (nbr != start) {
            dist[nbr] = nd;
          }
          que.emplace(-nd, nbr);
        }
      }
    }
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll INF = 1e18;
const ll M = 3 * 1e5 + 10, B = sqrt(M) + 10;
// バケット i は [i*B, (i+1)*B) の記録を持つ
 
// a_s,...,a_t の xor を返す
ll getxor(int s, int t, vll &a, vll &xors){
    ll ret = 0;
    int st = s / B, gt = t / B;

    //... || ... s ... t ... || ...
    //直接計算
    if (st == gt){
        for (int i = s; i <= t; i++) ret ^= a[i];
    }
    //... s ... || (被覆されるパケット)  || ... t ...
    else{
        //端が属するパケット内は直接計算
        for (int i = s; i < (st + 1) * B; i++) ret ^= a[i];
        for (int i = gt * B; i <= t; i++) ret ^= a[i];
        //被覆されるパケットはパケット単位で調査する
        for (int i = st + 1; i < gt; i++) ret ^= xors[i];
    }
    return ret;
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, q;
    cin >> n >> q;
    vll a(n), xors(B);
    REP(i, n) {
        cin >> a[i];
        xors[i / B] ^= a[i];
    }
    while (q--) {
        ll t, x, y;
        cin >> t >> x >> y;
        if(t == 1){
            x--;
            a[x] ^= y;
            xors[x / B] ^= y;
        }
        else{
            x--, y--;
            cout << getxor(x, y, a, xors) << endl;
        }
    }
    return 0;
}
