You are given a string S and an array of strings [t_1, t_2, ..., t_k]. Each string t_i consists of lowercase Latin letters from a to n; S consists of lowercase Latin letters from a to n and no more than 14 question marks.

Each string t_i has its cost c_i — an integer number. The value of some string T is calculated as ∑_{i = 1}^{k} F(T, t_i) ⋅ c_i, where F(T, t_i) is the number of occurences of string t_i in T as a substring. For example, F(aaabaaa, aa) = 4.

You have to replace all question marks in S with pairwise distinct lowercase Latin letters from a to n so the value of S is maximum possible.

Input

The first line contains one integer k (1 ≤ k ≤ 1000) — the number of strings in the array [t_1, t_2, ..., t_k].

Then k lines follow, each containing one string t_i (consisting of lowercase Latin letters from a to n) and one integer c_i (1 ≤ |t_i| ≤ 1000, -10^6 ≤ c_i ≤ 10^6). The sum of lengths of all strings t_i does not exceed 1000.

The last line contains one string S (1 ≤ |S| ≤ 4 ⋅ 10^5) consisting of lowercase Latin letters from a to n and question marks. The number of question marks in S is not greater than 14.

Output

Print one integer — the maximum value of S after replacing all question marks with pairwise distinct lowercase Latin letters from a to n.

Examples

Input


4
abc -10
a 1
b 1
c 3
?b?


Output


5


Input


2
a 1
a 1
?


Output


2


Input


3
a 1
b 3
ab 4
ab


Output


8


Input


1
a -1
?????????????


Output


0


Input


1
a -1
??????????????


Output


-1
#include <bits/stdc++.h>
namespace IPT {
const int L = 1 << 21;
char buf[L], *front = buf, *end = buf;
char GetChar() {
  if (front == end) end = buf + fread(front = buf, 1, L, stdin);
  return (front == end) ? -1 : *(front++);
}
template <typename T>
inline void qr(T &x) {
  char ch = GetChar(), lst = 0;
  x = 0;
  while (!isdigit(ch)) lst = ch, ch = GetChar();
  while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = GetChar();
  if (lst == '-') x = -x;
}
template <typename T>
void qra(T *const __ary, int __n) {
  for (int i = 0; i < __n; ++i) qr(__ary[i]);
}
template <typename T>
int qrs(T *p) {
  T *beg = p;
  do *p = GetChar();
  while ((!isalnum(*p)) && (*p != '?'));
  do *(++p) = GetChar();
  while ((isalnum(*p)) || (*p == '?'));
  *p = 0;
  return p - beg;
}
template <typename T>
void qrdb(T &x) {
  char ch = GetChar(), lst = 0;
  x = 0;
  while (!isdigit(ch)) lst = ch, ch = GetChar();
  while (isdigit(ch)) {
    x = x * 10 + (ch - '0');
    ch = GetChar();
  }
  if (ch == '.') {
    ch = GetChar();
    for (double t = 0.1; isdigit(ch); t *= 0.1) {
      x += (t * (ch - '0'));
      ch = GetChar();
    }
  }
  if (lst == '-') x = -x;
}
}  // namespace IPT
namespace OPT {
const int L = 30;
char buf[L];
template <typename T>
inline void qw(T x, const char aft = 0) {
  if (x < 0) {
    x = -x, putchar('-');
  }
  int top = 0;
  do {
    buf[++top] = static_cast<char>(x % 10 + '0');
  } while (x /= 10);
  while (top) putchar(buf[top--]);
  if (aft) putchar(aft);
}
template <typename T>
void qwa(T *const __ary, int __n, const char e1, const char e2) {
  int __dn = __n - 1;
  for (int i = 0; i < __dn; ++i) qw(__ary[i], e1);
  qw(__ary[__dn], e2);
}
template <typename T>
void qws(T *p, const int __n, const char ed) {
  for (int i = 0; i < __n; ++i) putchar(p[i]);
  if (ed) putchar(ed);
}
template <typename T>
void qws(T *p, const char ed) {
  while (*p) putchar(*p++);
  if (ed) putchar(ed);
}
}  // namespace OPT
using IPT::qr;
using IPT::qra;
using IPT::qrdb;
using IPT::qrs;
using OPT::qw;
using OPT::qwa;
using OPT::qws;
namespace Fusu {
void Main();
}
int main() {
  ;
  Fusu::Main();
  return 0;
}
namespace Fusu {
const int maxt = 14;
const int maxh = 1005;
const int maxn = 400005;
const int maxs = (1 << maxt) + 5;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
void Init();
void Calc();
void Build();
void Main() {
  Init();
  Build();
  Calc();
}
int n;
char s[maxn];
struct Node {
  long long v;
  Node *trans[maxt], *fail;
  std::vector<Node *> fson;
};
Node Mem[maxn], *pool = Mem + 1, *rot = Mem;
void Init() {
  qr(n);
  for (int i = 1, len; i <= n; ++i) {
    len = qrs(s + 1);
    auto u = rot;
    for (int j = 1, k = s[j] - 'a'; j <= len; k = s[++j] - 'a') {
      u = u->trans[k] ? u->trans[k] : (u->trans[k] = pool++);
    }
    qr(len);
    u->v += len;
  }
}
void dfs(Node *const u) {
  for (auto v : u->fson) {
    v->v += u->v;
    dfs(v);
  }
}
std::queue<Node *> Q;
void Build() {
  for (auto &v : rot->trans)
    if (v != nullptr) {
      v->fail = rot;
      Q.push(v);
    } else {
      v = rot;
    }
  for (Node *u, *v; !Q.empty(); Q.pop()) {
    u = Q.front();
    v = u->fail;
    v->fson.push_back(u);
    for (int i = 0; i < maxt; ++i)
      if (u->trans[i]) {
        u->trans[i]->fail = v->trans[i];
        Q.push(u->trans[i]);
      } else {
        u->trans[i] = v->trans[i];
      }
  }
  dfs(rot);
}
std::vector<std::pair<int, int> > rng;
long long f[maxh][maxs];
std::vector<int> sta[maxt];
inline int countbit(int x) {
  int ret = 0;
  while (x) {
    ++ret;
    x &= x - 1;
  }
  return ret;
}
void Calc() {
  int nn = qrs(s + 1);
  int tn = pool - Mem;
  rng.push_back({0, 0});
  int jk = 1;
  for (int i = 1; i <= nn; ++i)
    if (s[i] == '?') {
      rng.push_back({jk, i});
      jk = i + 1;
    }
  n = rng.size();
  int upc = (1 << 14) - 1;
  for (int i = 0; i <= upc; ++i) {
    sta[countbit(i)].push_back(i);
  }
  memset(f, -0x3f, sizeof f);
  f[0][0] = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < tn; ++j) {
      long long tv = 0;
      auto u = Mem + j;
      for (int k = rng[i].first; k < rng[i].second; ++k) {
        u = u->trans[s[k] - 'a'];
        tv += u->v;
      }
      for (auto s : sta[i - 1]) {
        for (int k = 0, ss = 1 << k; k < maxt; ss = 1 << ++k)
          if ((s & ss) == 0) {
            int pp = u->trans[k] - Mem;
            f[pp][s | ss] =
                std::max(f[pp][s | ss], f[j][s] + tv + u->trans[k]->v);
          }
      }
    }
  }
  long long ans = -INF;
  for (int i = 0; i < tn; ++i) {
    long long tv = 0;
    auto u = Mem + i;
    for (int k = jk; k <= nn; ++k) {
      u = u->trans[s[k] - 'a'];
      tv += u->v;
    }
    for (auto s : sta[n - 1]) {
      ans = std::max(ans, f[i][s] + tv);
    }
  }
  qw(ans, '\n');
}
}  // namespace Fusu
