#include <bits/stdc++.h>
using namespace std;
int n, q, baseNode[4 * 100010];
long long numbers[100010][10], tree[4 * 100010][10];
int nxt[4 * 100010][10];
void updFromChildren(int i) {
  for (int j = 0; j < 10; j++) {
    tree[i][j] = tree[2 * i][j] + tree[2 * i + 1][j];
  }
}
void build(int left, int right, int i) {
  if (left == right) {
    for (int j = 0; j < 10; j++) {
      tree[i][j] = numbers[left][j];
    }
    baseNode[i] = true;
    return;
  }
  int mid = (left + right) / 2;
  build(left, mid, 2 * i);
  build(mid + 1, right, 2 * i + 1);
  updFromChildren(i);
}
int n1[10], n2[10];
long long sum[10];
void push(int i, int left, int right) {
  for (int j = 0; j < 10; j++) {
    sum[j] = 0;
  }
  if (!baseNode[i]) {
    for (int j = 0; j < 10; j++) {
      n1[j] = nxt[i][nxt[2 * i][j]];
      n2[j] = nxt[i][nxt[2 * i + 1][j]];
    }
    for (int j = 0; j < 10; j++) {
      nxt[2 * i][j] = n1[j];
      nxt[2 * i + 1][j] = n2[j];
    }
  }
  for (int j = 0; j < 10; j++) {
    sum[nxt[i][j]] += tree[i][j];
  }
  for (int j = 0; j < 10; j++) {
    tree[i][j] = sum[j];
    nxt[i][j] = j;
  }
}
void update(int i, int left, int right, int start, int end,
            pair<int, int> change) {
  if (i >= 4 * 100010) return;
  push(i, left, right);
  if (start > right || left > end) return;
  if (start <= left && right <= end) {
    nxt[i][change.first] = change.second;
    push(i, left, right);
    return;
  }
  int mid = (left + right) / 2;
  update(2 * i, left, mid, start, end, change);
  update(2 * i + 1, mid + 1, right, start, end, change);
  updFromChildren(i);
}
long long query(int i, int left, int right, int start, int end) {
  if (i >= 4 * 100010) return 0;
  push(i, left, right);
  if (start > right || left > end) return 0;
  if (start <= left && right <= end) {
    long long answer = 0;
    for (int j = 1; j < 10; j++) {
      answer += (long long)(j)*tree[i][j];
    }
    return answer;
  }
  int mid = (left + right) / 2;
  return query(2 * i, left, mid, start, end) +
         query(2 * i + 1, mid + 1, right, start, end);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> q;
  int tenToThePowerOf[9];
  tenToThePowerOf[0] = 1;
  for (int i = 1; i < 9; i++) {
    tenToThePowerOf[i] = tenToThePowerOf[i - 1] * 10;
  }
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    for (int j = 0; j < 10; j++) {
      numbers[i][j] = 0;
    }
    for (int j = 0; j < 9; j++) {
      if (temp == 0) break;
      int cur = temp % 10;
      numbers[i][cur] += tenToThePowerOf[j];
      temp /= 10;
    }
  }
  for (int i = 0; i < 4 * 100010; i++) {
    for (int j = 0; j < 10; j++) {
      tree[i][j] = 0;
      nxt[i][j] = j;
    }
  }
  build(0, n - 1, 1);
  for (int i = 0; i < q; i++) {
    int id;
    cin >> id;
    if (id == 1) {
      int l, r, x, y;
      cin >> l >> r >> x >> y;
      l--;
      r--;
      update(1, 0, n - 1, l, r, make_pair(x, y));
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      cout << query(1, 0, n - 1, l, r) << '\n';
    }
  }
}
