#include <bits/stdc++.h>
using namespace std;
const int N = int(1e5) + 5;
int n, q;
long long outcome;
char s[100];
struct seg {
  int p[10];
  long long sum[10];
  void appendopt(pair<int, int> opt) {
    if (opt.first == opt.second) return;
    for (int i = 0; i < 10; i++)
      if (p[i] == opt.first) p[i] = opt.second;
    sum[opt.second] += sum[opt.first];
    sum[opt.first] = 0;
  }
  void getdown(const seg &fa) {
    static long long tmp[10];
    for (int i = 0; i < 10; i++) tmp[i] = 0;
    for (int i = 0; i < 10; i++) tmp[fa.p[i]] += sum[i];
    for (int i = 0; i < 10; i++) sum[i] = tmp[i];
    for (int i = 0; i < 10; i++) p[i] = fa.p[p[i]];
  }
  void query() {
    for (int i = 0; i < 10; i++) outcome += i * sum[i];
  }
} t[N * 4];
void update(int cur) {
  for (int i = 0; i < 10; i++)
    t[cur].sum[i] = t[cur << 1].sum[i] + t[cur << 1 | 1].sum[i];
}
void down(int cur) {
  t[cur << 1].getdown(t[cur]);
  t[cur << 1 | 1].getdown(t[cur]);
  for (int i = 0; i < 10; i++) t[cur].p[i] = i;
}
void build(int cur, int beg, int end) {
  for (int i = 0; i < 10; i++) t[cur].p[i] = i;
  if (end - beg == 1) {
    scanf("%s", s);
    reverse(s, s + strlen(s));
    for (int i = 0, w = 1; s[i]; i++, w *= 10) t[cur].sum[s[i] - '0'] += w;
    return;
  }
  int mid = (beg + end) >> 1;
  build(cur << 1, beg, mid);
  build(cur << 1 | 1, mid, end);
  update(cur);
}
void modify(int cur, int beg, int end, int L, int R,
            const pair<int, int> &opt) {
  if (end <= L || beg >= R) return;
  if (beg >= L && end <= R) {
    t[cur].appendopt(opt);
    return;
  }
  down(cur);
  int mid = (beg + end) >> 1;
  modify(cur << 1, beg, mid, L, R, opt);
  modify(cur << 1 | 1, mid, end, L, R, opt);
  update(cur);
}
void query(int cur, int beg, int end, int L, int R) {
  if (end <= L || beg >= R) return;
  if (beg >= L && end <= R) {
    t[cur].query();
    return;
  }
  down(cur);
  int mid = (beg + end) >> 1;
  query(cur << 1, beg, mid, L, R);
  query(cur << 1 | 1, mid, end, L, R);
}
int main() {
  scanf("%d%d", &n, &q);
  build(1, 0, n);
  while (q--) {
    int type, l, r;
    scanf("%d%d%d", &type, &l, &r);
    l--;
    if (type == 1) {
      int x, y;
      scanf("%d%d", &x, &y);
      if (x != y) modify(1, 0, n, l, r, pair<int, int>(x, y));
    } else {
      outcome = 0;
      query(1, 0, n, l, r);
      printf("%I64d\n", outcome);
    }
  }
}
