#include <bits/stdc++.h>
struct SGT {
  int n;
  long long a[10][100005 << 2];
  int tag[10][100005 << 2];
  void update(int* change, int cur) {
    long long tmp[10] = {0};
    for (int i = 0; i <= 9; ++i) tmp[change[i]] += a[i][cur];
    for (int i = 0; i <= 9; ++i) a[i][cur] = tmp[i];
    for (int i = 0; i <= 9; ++i) tag[i][cur] = change[tag[i][cur]];
  }
  void push_up(int cur) {
    for (int i = 0; i <= 9; ++i)
      a[i][cur] = a[i][(cur << 1)] + a[i][((cur << 1) | 1)];
  }
  void push_down(int cur) {
    int change[10];
    for (int i = 0; i <= 9; ++i) change[i] = tag[i][cur];
    update(change, (cur << 1));
    update(change, ((cur << 1) | 1));
    for (int i = 0; i <= 9; ++i) tag[i][cur] = i;
  }
  void build(int left, int right, int cur) {
    for (int i = 0; i <= 9; ++i) tag[i][cur] = i;
    if (left == right) {
      int tmp;
      scanf("%d", &tmp);
      for (int x = 1; tmp; tmp /= 10, x *= 10) a[tmp % 10][cur] += x;
      return;
    }
    int mid = (left + right) >> 1;
    build(left, mid, (cur << 1));
    build(mid + 1, right, ((cur << 1) | 1));
    push_up(cur);
  }
  void build(int size) {
    n = size;
    build(1, n, 1);
  }
  void update(int x, int y, int dgt1, int dgt2, int left, int right, int cur) {
    if (left >= x && right <= y) {
      int change[10];
      for (int i = 0; i <= 9; ++i) change[i] = i == dgt1 ? dgt2 : i;
      update(change, cur);
      return;
    }
    push_down(cur);
    int mid = (left + right) >> 1;
    if (x <= mid) update(x, y, dgt1, dgt2, left, mid, (cur << 1));
    if (y > mid) update(x, y, dgt1, dgt2, mid + 1, right, ((cur << 1) | 1));
    push_up(cur);
  }
  long long query(int x, int y, int left, int right, int cur) {
    if (left >= x && right <= y) {
      long long ret = 0;
      for (int i = 0; i <= 9; ++i) ret += a[i][cur] * i;
      return ret;
    }
    push_down(cur);
    long long ret = 0;
    int mid = (left + right) >> 1;
    if (x <= mid) ret += query(x, y, left, mid, (cur << 1));
    if (y > mid) ret += query(x, y, mid + 1, right, ((cur << 1) | 1));
    return ret;
  }
  void update(int x, int y, int dgt1, int dgt2) {
    update(x, y, dgt1, dgt2, 1, n, 1);
  }
  long long query(int x, int y) { return query(x, y, 1, n, 1); }
};
SGT s;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  s.build(n);
  int opt, x, y, dgt1, dgt2;
  while (m--) {
    scanf("%d %d %d", &opt, &x, &y);
    if (opt == 1) {
      scanf("%d %d", &dgt1, &dgt2);
      s.update(x, y, dgt1, dgt2);
    } else
      printf("%lld\n", s.query(x, y));
  }
  return 0;
}
