#include <bits/stdc++.h>
using namespace std;
char str[700000];
int Max[700000], L[700000], R[700000], ls[700000], rs[700000], root[700000],
    tot = 0, lcp[700000], n, last[700000], a[700000], sta[700000], tmp[700000];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
vector<int> vec[700000];
namespace Tree {
int mx[700000];
inline void update(int l, int r, int x, int p) {
  if (l == r) {
    mx[x] = vec[p].size();
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    update(l, mid, x << 1, p);
  else
    update(mid + 1, r, x << 1 | 1, p);
  mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
}
inline int query(int l, int r, int x, int ll, int rr) {
  if (ll <= l && r <= rr) return mx[x];
  int mid = (l + r) >> 1, res = 0;
  if (ll <= mid) res = max(res, query(l, mid, x << 1, ll, rr));
  if (rr > mid) res = max(res, query(mid + 1, r, x << 1 | 1, ll, rr));
  return res;
}
};  // namespace Tree
inline int find(int x) {
  int i;
  for (i = 0; i < min(vec[x].size(), vec[x - 1].size()); ++i)
    if (vec[x][i] != vec[x - 1][i]) return i;
  return min(vec[x].size(), vec[x - 1].size());
}
inline void pushup(int x, int l, int r) {
  int mid = (l + r) >> 1;
  Max[x] = max(R[ls[x]] + L[rs[x]], max(Max[ls[x]], Max[rs[x]]));
  L[x] = L[ls[x]], R[x] = R[rs[x]];
  if (L[ls[x]] == (mid - l + 1)) L[x] += L[rs[x]];
  if (R[rs[x]] == (r - mid)) R[x] += R[ls[x]];
}
inline void update(int &x, int l, int r, int p, int opt) {
  if (!x) x = ++tot;
  if (l == r) {
    Max[x] = L[x] = R[x] = opt;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    update(ls[x], l, mid, p, opt);
  else
    update(rs[x], mid + 1, r, p, opt);
  pushup(x, l, r);
}
inline void modify(int x, int opt) {
  int i, p = 0;
  if (lcp[x] <= 70) {
    for (i = 1; i <= lcp[x]; ++i) update(root[i], 1, n, x, opt);
  } else if (!opt) {
    for (i = 1; i <= 70; ++i) update(root[i], 1, n, x, 0);
    p = 0;
    while (last[p] != x) p = last[p];
    last[p] = last[x], last[x] = 0;
  } else {
    for (i = 1; i <= 70; ++i) update(root[i], 1, n, x, 1);
    p = 0;
    while (last[p] && last[p] < x) p = last[p];
    last[x] = last[p], last[p] = x;
  }
}
inline int query(int x, int l, int r, int ll, int rr) {
  if (!x) return 0;
  if (ll <= l && r <= rr) return Max[x];
  int mid = (l + r) >> 1, res = 0;
  if (ll <= mid) res = max(res, query(ls[x], l, mid, ll, rr));
  if (rr > mid) res = max(res, query(rs[x], mid + 1, r, ll, rr));
  if (ll <= mid && rr > mid)
    res = max(res, min(R[ls[x]], mid - ll + 1) + min(L[rs[x]], rr - mid));
  return res;
}
inline int solve(int l, int r) {
  int p = 0, num = 0, top = 0, i, res = 0;
  while (last[p]) p = last[p], a[++num] = p, num -= (p < l || p > r);
  sta[0] = a[1] - 1;
  for (i = 1; i <= num; ++i) {
    if (top && a[i] != sta[top] + 1) top = 0, sta[0] = a[i] - 1;
    while (top && lcp[a[i]] <= lcp[sta[top]]) --top;
    tmp[i] = sta[top], sta[++top] = a[i];
  }
  top = 0, sta[0] = a[num] + 1;
  for (i = num; i; --i) {
    if (top && a[i] != sta[top] - 1) top = 0, sta[0] = a[i] + 1;
    while (top && lcp[a[i]] <= lcp[sta[top]]) --top;
    res = max(res, lcp[a[i]] * (sta[top] - tmp[i]));
    sta[++top] = a[i];
  }
  return res;
}
int main() {
  int q, lens, l, r, j, i, opt, w, ans = 0, x;
  n = read(), q = read();
  for (i = 1; i <= n; ++i) {
    scanf("%s", str + 1), lens = strlen(str + 1);
    for (j = 1; j <= lens; ++j) vec[i].push_back(str[j] - 'a');
    Tree::update(1, n, 1, i);
    lcp[i] = find(i);
    modify(i, 1);
  }
  while (q--) {
    opt = read();
    if (opt == 1) {
      l = read(), r = read();
      ans = Tree::query(1, n, 1, l, r);
      if (l == r) {
        printf("%d\n", ans);
        continue;
      }
      for (i = 1; i <= 70; ++i)
        w = query(root[i], 1, n, l + 1, r),
        ans = max(ans, i * (w > 0 ? w + 1 : 0));
      ans = max(ans, solve(l + 1, r));
      printf("%d\n", ans);
    } else {
      x = read(), scanf("%s", str + 1), lens = strlen(str + 1);
      vec[x].clear();
      for (i = 1; i <= lens; ++i) vec[x].push_back(str[i] - 'a');
      Tree::update(1, n, 1, x);
      modify(x, 0), lcp[x] = find(x), modify(x, 1);
      if (x == n) continue;
      modify(x + 1, 0), lcp[x + 1] = find(x + 1), modify(x + 1, 1);
    }
  }
  return 0;
}
