#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 100;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
struct node {
  long long s, lz[10], val[10];
  node() {
    s = 0;
    for (long long i = 0; i < 10; i++) {
      lz[i] = i;
      val[i] = 0;
    }
  }
};
long long n, q, a[maxn];
node seg[maxn << 2];
void bld(long long id, long long s, long long e) {
  if (e - s == 1) {
    seg[id].s = a[s];
    long long x = 1;
    while (a[s]) {
      seg[id].val[a[s] % 10] += x;
      x *= 10;
      a[s] /= 10;
    }
    return;
  }
  long long mid = (s + e) >> 1;
  bld((id << 1), s, mid);
  bld((id << 1 | 1), mid, e);
  seg[id].s = seg[(id << 1)].s + seg[(id << 1 | 1)].s;
  for (long long i = 0; i < 10; i++) {
    seg[id].val[i] = seg[(id << 1)].val[i] + seg[(id << 1 | 1)].val[i];
  }
  return;
}
void Do(long long id, long long x, long long y) {
  if (x == y) return;
  seg[id].s += seg[id].val[x] * (y - x);
  seg[id].val[y] += seg[id].val[x];
  seg[id].val[x] = 0;
  for (long long i = 0; i < 10; i++) {
    if (seg[id].lz[i] == x) seg[id].lz[i] = y;
  }
  return;
}
void shift(long long id) {
  long long ds = 0;
  long long dx[10];
  fill(dx, dx + 10, 0);
  for (long long i = 0; i < 10; i++) {
    dx[seg[id].lz[i]] += seg[(id << 1)].val[i];
    seg[(id << 1)].lz[i] = seg[id].lz[seg[(id << 1)].lz[i]];
    ds += seg[(id << 1)].val[i] * (seg[id].lz[i] - i);
  }
  seg[(id << 1)].s += ds;
  for (long long i = 0; i < 10; i++) {
    seg[(id << 1)].val[i] = dx[i];
  }
  fill(dx, dx + 10, 0);
  ds = 0;
  for (long long i = 0; i < 10; i++) {
    dx[seg[id].lz[i]] += seg[(id << 1 | 1)].val[i];
    seg[(id << 1 | 1)].lz[i] = seg[id].lz[seg[(id << 1 | 1)].lz[i]];
    ds += seg[(id << 1 | 1)].val[i] * (seg[id].lz[i] - i);
  }
  seg[(id << 1 | 1)].s += ds;
  for (long long i = 0; i < 10; i++) {
    seg[(id << 1 | 1)].val[i] = dx[i];
    seg[id].lz[i] = i;
  }
  return;
}
void upd(long long id, long long s, long long e, long long l, long long r,
         long long x, long long y) {
  if (r <= s || e <= l) return;
  if (l <= s && e <= r) {
    Do(id, x, y);
    return;
  }
  long long mid = (s + e) >> 1;
  shift(id);
  upd((id << 1), s, mid, l, r, x, y);
  upd((id << 1 | 1), mid, e, l, r, x, y);
  seg[id].s = seg[(id << 1)].s + seg[(id << 1 | 1)].s;
  for (long long i = 0; i < 10; i++) {
    seg[id].val[i] = seg[(id << 1)].val[i] + seg[(id << 1 | 1)].val[i];
  }
  return;
}
long long get(long long id, long long s, long long e, long long l,
              long long r) {
  if (r <= s || e <= l) return 0;
  if (l <= s && e <= r) {
    return seg[id].s;
  }
  long long mid = (s + e) >> 1;
  shift(id);
  return get((id << 1), s, mid, l, r) + get((id << 1 | 1), mid, e, l, r);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> q;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  bld(1, 0, n);
  for (long long i = 0; i < q; i++) {
    long long t, l, r, x, y;
    cin >> t >> l >> r;
    if (t == 2) {
      cout << get(1, 0, n, l - 1, r) << '\n';
    } else {
      cin >> x >> y;
      upd(1, 0, n, l - 1, r, x, y);
    }
  }
  return 0;
}
