#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, q, a[maxn];
struct node {
  long long sum[10];
  int nx[10];
  void merge(node L, node R) {
    for (int d = 0; d <= 9; ++d) sum[d] = L.sum[d] + R.sum[d];
    for (int d = 0; d <= 9; ++d) nx[d] = d;
  }
} seg[4 * maxn];
void build(int idx, int i, int j) {
  if (i == j) {
    for (int d = 0; d <= 9; ++d) seg[idx].nx[d] = d;
    long long c = 1LL;
    int x = a[i];
    while (x) {
      seg[idx].sum[x % 10] += c;
      x /= 10;
      c *= 10;
    }
    return;
  }
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  build(left, i, mid);
  build(right, mid + 1, j);
  seg[idx].merge(seg[left], seg[right]);
}
void refresh(int idx, int i, int j) {
  long long sum[10];
  int nxL[10];
  int nxR[10];
  int left = idx << 1;
  int right = left | 1;
  if (i != j) {
    for (int d = 0; d <= 9; ++d) {
      nxL[d] = seg[idx].nx[seg[left].nx[d]];
      nxR[d] = seg[idx].nx[seg[right].nx[d]];
    }
    for (int d = 0; d <= 9; ++d) {
      seg[left].nx[d] = nxL[d];
      seg[right].nx[d] = nxR[d];
    }
  }
  for (int d = 0; d <= 9; ++d) sum[d] = 0;
  for (int d = 0; d <= 9; ++d) sum[seg[idx].nx[d]] += seg[idx].sum[d];
  for (int d = 0; d <= 9; ++d) {
    seg[idx].nx[d] = d;
    seg[idx].sum[d] = sum[d];
  }
}
void update(int idx, int i, int j, int l, int r, int x, int y) {
  refresh(idx, i, j);
  if (i > j || j < l || r < i) return;
  if (l <= i && j <= r) {
    seg[idx].nx[x] = y;
    refresh(idx, i, j);
    return;
  }
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  update(left, i, mid, l, r, x, y);
  update(right, mid + 1, j, l, r, x, y);
  seg[idx].merge(seg[left], seg[right]);
}
long long query(int idx, int i, int j, int l, int r) {
  refresh(idx, i, j);
  if (i > j || j < l || r < i) return 0;
  if (l <= i && j <= r) {
    long long sum = 0;
    for (int d = 0; d <= 9; ++d) sum += 1LL * d * seg[idx].sum[d];
    return sum;
  }
  int mid = (i + j) >> 1;
  int left = idx << 1;
  int right = left | 1;
  return query(left, i, mid, l, r) + query(right, mid + 1, j, l, r);
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  build(1, 1, n);
  while (q--) {
    int type, l, r;
    scanf("%d %d %d", &type, &l, &r);
    if (type == 1) {
      int x, y;
      scanf("%d %d", &x, &y);
      update(1, 1, n, l, r, x, y);
    } else
      printf("%lld\n", query(1, 1, n, l, r));
  }
  return 0;
}
