#include <bits/stdc++.h>
using namespace std;
long long int n, q, a[100005];
string arr[100005];
long long int seg[500001][10];
long long int pen[500001][10];
void build(long long int idx, long long int lo, long long int hi) {
  for (long long int i = 0; i <= 9; ++i) pen[idx][i] = i;
  if (lo == hi) {
    long long int mul = 1;
    for (long long int i = 0; i <= arr[lo].size() - 1; ++i) {
      seg[idx][arr[lo][i] - '0'] += mul;
      mul *= 10;
    }
    return;
  }
  long long int mid = (lo + hi) / 2;
  build(2 * idx, lo, mid);
  build(2 * idx + 1, mid + 1, hi);
  for (long long int i = 0; i <= 9; ++i)
    seg[idx][i] = seg[2 * idx][i] + seg[2 * idx + 1][i];
}
void lazyprop(long long int idx, long long int lo, long long int hi) {
  long long int tem[10];
  for (long long int i = 0; i <= 9; ++i) tem[i] = 0;
  for (long long int i = 0; i <= 9; ++i) tem[pen[idx][i]] += seg[idx][i];
  for (long long int i = 0; i <= 9; ++i) seg[idx][i] = tem[i];
  if (lo != hi) {
    for (long long int i = 0; i <= 9; ++i) tem[i] = 0;
    for (long long int i = 0; i <= 9; ++i) tem[i] = pen[idx][pen[2 * idx][i]];
    for (long long int i = 0; i <= 9; ++i) pen[2 * idx][i] = tem[i];
    for (long long int i = 0; i <= 9; ++i) tem[i] = 0;
    for (long long int i = 0; i <= 9; ++i)
      tem[i] = pen[idx][pen[2 * idx + 1][i]];
    for (long long int i = 0; i <= 9; ++i) pen[2 * idx + 1][i] = tem[i];
  }
  for (long long int i = 0; i <= 9; ++i) pen[idx][i] = i;
}
void update(long long int idx, long long int lo, long long int hi,
            long long int st, long long int en, long long int x,
            long long int y) {
  if (st == lo && hi == en) {
    if (lo == hi) {
      lazyprop(idx, lo, hi);
      seg[idx][y] += seg[idx][x];
      seg[idx][x] = 0;
      return;
    } else {
      lazyprop(idx, lo, hi);
      pen[idx][x] = y;
    }
    return;
  }
  lazyprop(idx, lo, hi);
  long long int mid = (lo + hi) / 2;
  if (en <= mid)
    update(2 * idx, lo, mid, st, en, x, y);
  else if (st > mid)
    update(2 * idx + 1, mid + 1, hi, st, en, x, y);
  else {
    update(2 * idx, lo, mid, st, mid, x, y);
    update(2 * idx + 1, mid + 1, hi, mid + 1, en, x, y);
  }
  for (long long int i = 0; i <= 9; ++i) seg[idx][i] = 0;
  for (long long int i = 0; i <= 9; ++i)
    seg[idx][pen[2 * idx][i]] += seg[2 * idx][i];
  for (long long int i = 0; i <= 9; ++i)
    seg[idx][pen[2 * idx + 1][i]] += seg[2 * idx + 1][i];
}
long long query(long long int idx, long long int lo, long long int hi,
                long long int st, long long int en) {
  if (lo == st && hi == en) {
    long long int tem[10];
    for (long long int i = 0; i <= 9; ++i) tem[i] = 0;
    for (long long int i = 0; i <= 9; ++i) tem[pen[idx][i]] += seg[idx][i];
    long long ret = 0;
    for (long long int i = 0; i <= 9; ++i) ret += (long long)tem[i] * i;
    return ret;
  }
  lazyprop(idx, lo, hi);
  long long int mid = (lo + hi) / 2;
  if (en <= mid)
    return query(2 * idx, lo, mid, st, en);
  else if (st > mid)
    return query(2 * idx + 1, mid + 1, hi, st, en);
  else
    return (query(2 * idx, lo, mid, st, mid) +
            query(2 * idx + 1, mid + 1, hi, mid + 1, en));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (long long int i = 1; i <= n; ++i) cin >> a[i];
  for (long long int i = 1; i <= n; ++i) {
    long long int v = a[i];
    while (v) {
      arr[i].push_back(v % 10 + '0');
      v /= 10;
    }
  }
  build(1, 1, n);
  while (q--) {
    long long int ty;
    cin >> ty;
    if (ty == 1) {
      long long int l, r, x, y;
      cin >> l >> r >> x >> y;
      if (x == y) continue;
      update(1, 1, n, l, r, x, y);
    } else {
      long long int l, r;
      cin >> l >> r;
      long long ans = query(1, 1, n, l, r);
      cout << ans << '\n';
    }
  }
}
