#include <bits/stdc++.h>
using namespace std;
struct change {
  int from, to;
  change(int from = 0, int to = 0) : from(from), to(to) {}
};
struct Tree {
  long long s[10], sum;
  int to[10];
  bool lz;
};
int N, Q, a[100010];
Tree t[400010];
void build(int nod, int l, int r) {
  for (int i = 0; i < 10; i++) t[nod].to[i] = i;
  if (l == r) {
    t[nod].sum = a[l];
    long long p10 = 1;
    while (a[l]) t[nod].s[a[l] % 10] += p10, a[l] /= 10, p10 *= 10;
    return;
  }
  int mid = (l + r) / 2;
  build(nod * 2, l, mid);
  build(nod * 2 + 1, mid + 1, r);
  for (int i = 0; i < 10; i++)
    t[nod].s[i] = t[nod * 2].s[i] + t[nod * 2 + 1].s[i];
  t[nod].sum = t[nod * 2].sum + t[nod * 2 + 1].sum;
}
void unlazy(int nod, int l, int r) {
  if (!t[nod].lz) return;
  long long val[10], i;
  memset(val, 0, sizeof(val));
  for (i = 0; i < 10; i++) val[t[nod].to[i]] += t[nod].s[i];
  t[nod].sum = 0;
  for (i = 0; i < 10; i++) {
    t[nod].s[i] = val[i];
    t[nod].sum += i * val[i];
  }
  if (l != r) {
    for (i = 0; i < 10; i++) {
      t[nod * 2].to[i] = t[nod].to[t[nod * 2].to[i]];
      t[nod * 2 + 1].to[i] = t[nod].to[t[nod * 2 + 1].to[i]];
    }
    t[nod * 2].lz = t[nod * 2 + 1].lz = 1;
  }
  for (i = 0; i < 10; i++) t[nod].to[i] = i;
  t[nod].lz = 0;
}
void update(int nod, int l, int r, int ql, int qr, int fr, int to) {
  if (ql <= l && r <= qr) {
    for (int i = 0; i < 10; i++)
      if (t[nod].to[i] == fr) t[nod].to[i] = to;
    t[nod].lz = 1;
    return;
  }
  unlazy(nod, l, r);
  int mid = (l + r) / 2;
  if (ql <= mid) update(nod * 2, l, mid, ql, qr, fr, to);
  if (mid < qr) update(nod * 2 + 1, mid + 1, r, ql, qr, fr, to);
  unlazy(nod * 2, l, mid);
  unlazy(nod * 2 + 1, mid + 1, r);
  for (int i = 0; i < 10; i++)
    t[nod].s[i] = t[nod * 2].s[i] + t[nod * 2 + 1].s[i];
  t[nod].sum = t[nod * 2].sum + t[nod * 2 + 1].sum;
}
long long query(int nod, int l, int r, int ql, int qr) {
  unlazy(nod, l, r);
  if (ql <= l && r <= qr) return t[nod].sum;
  int mid = (l + r) / 2;
  long long res = 0;
  if (ql <= mid) res += query(nod * 2, l, mid, ql, qr);
  if (mid < qr) res += query(nod * 2 + 1, mid + 1, r, ql, qr);
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> Q;
  int i;
  for (i = 1; i <= N; i++) cin >> a[i];
  build(1, 1, N);
  int tp, ql, qr, fr, to;
  while (Q--) {
    cin >> tp >> ql >> qr;
    if (tp == 1) {
      cin >> fr >> to;
      update(1, 1, N, ql, qr, fr, to);
    } else {
      cout << query(1, 1, N, ql, qr) << "\n";
    }
  }
  return 0;
}
