#include <bits/stdc++.h>
const long long N = 1e5 + 5;
using namespace std;
struct node {
  long long sum[10], lazy[10];
} lv[4 * N];
long long n, a[N], q;
void init(long long i, long long l, long long r) {
  for (long long k = 0; k < 10; k++) lv[i].lazy[k] = k;
  if (l == r) {
    long long x = 1, z;
    while (a[l] != 0) {
      z = a[l] % 10;
      lv[i].sum[z] += x;
      x *= 10;
      a[l] /= 10;
    }
    return;
  }
  long long mid = (l + r) / 2;
  init(i * 2, l, mid);
  init(i * 2 + 1, mid + 1, r);
  for (long long k = 0; k < 10; k++)
    lv[i].sum[k] = lv[i * 2].sum[k] + lv[i * 2 + 1].sum[k];
}
void dolazy(long long i, long long l, long long r) {
  if (l != r) {
    for (long long k = 0; k < 10; k++) {
      lv[i * 2].lazy[k] = lv[i].lazy[lv[i * 2].lazy[k]];
      lv[i * 2 + 1].lazy[k] = lv[i].lazy[lv[i * 2 + 1].lazy[k]];
    }
  }
  long long cur[10];
  for (long long k = 0; k < 10; k++) cur[k] = 0;
  for (long long k = 0; k < 10; k++) cur[lv[i].lazy[k]] += lv[i].sum[k];
  for (long long k = 0; k < 10; k++) lv[i].sum[k] = cur[k], lv[i].lazy[k] = k;
}
void update(long long i, long long l, long long r, long long L, long long R,
            long long x, long long y) {
  dolazy(i, l, r);
  if (L > r || l > R) return;
  if (L <= l && r <= R) {
    lv[i].lazy[x] = y;
    dolazy(i, l, r);
    return;
  }
  long long mid = (l + r) / 2;
  update(i * 2, l, mid, L, R, x, y);
  update(i * 2 + 1, mid + 1, r, L, R, x, y);
  for (long long k = 0; k < 10; k++)
    lv[i].sum[k] = lv[i * 2].sum[k] + lv[i * 2 + 1].sum[k];
}
long long get(long long i, long long l, long long r, long long L, long long R) {
  dolazy(i, l, r);
  if (L > r || l > R) return 0;
  if (L <= l && r <= R) {
    long long ans = 0;
    for (int k = 0; k < 10; k++) ans += lv[i].sum[k] * k;
    return ans;
  }
  long long mid = (l + r) / 2;
  return get(i * 2, l, mid, L, R) + get(i * 2 + 1, mid + 1, r, L, R);
}
int main() {
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  init(1, 1, n);
  while (q--) {
    long long query, l, r, x, y;
    cin >> query >> l >> r;
    if (query == 1) {
      cin >> x >> y;
      update(1, 1, n, l, r, x, y);
    } else {
      cout << get(1, 1, n, l, r) << "\n";
    }
  }
}
