#include <bits/stdc++.h>
using namespace std;
int dp[105][105][105], pre[105][105][105][3];
char s1[105], s2[105], vr[105];
int to[105][30];
void init() {
  int i, j, len = strlen(vr + 1);
  string s = vr + 1;
  for (i = 0; i <= len; i++)
    for (j = 0; j < 26; j++) {
      char ch = 'A' + j;
      if (ch == vr[i + 1])
        to[i][j] = i + 1;
      else {
        for (int k = i - 1; k >= 0; k--) {
          string tmp = s.substr(i - k, k) + ch;
          if (tmp == s.substr(0, k + 1)) {
            to[i][j] = k + 1;
            break;
          }
        }
      }
    }
}
int main() {
  scanf("%s%s%s", s1 + 1, s2 + 1, vr + 1);
  init();
  int i, j, k, len = strlen(vr + 1);
  int l1 = strlen(s1 + 1), l2 = strlen(s2 + 1);
  for (i = 0; i <= l1; i++)
    for (j = 0; j <= l2; j++)
      for (k = 0; k < len; k++) {
        if (dp[i][j + 1][k] < dp[i][j][k]) {
          dp[i][j + 1][k] = dp[i][j][k];
          pre[i][j + 1][k][0] = i;
          pre[i][j + 1][k][1] = j;
          pre[i][j + 1][k][2] = k;
        }
        if (dp[i + 1][j][k] < dp[i][j][k]) {
          dp[i + 1][j][k] = dp[i][j][k];
          pre[i + 1][j][k][0] = i;
          pre[i + 1][j][k][1] = j;
          pre[i + 1][j][k][2] = k;
        }
        if (i + 1 <= l1 && j + 1 <= l2 && (k == 0 || (k > 0 && dp[i][j][k]))) {
          if (s1[i + 1] == s2[j + 1]) {
            if (s1[i + 1] == vr[k + 1]) {
              if (dp[i + 1][j + 1][k + 1] < dp[i][j][k] + 1) {
                dp[i + 1][j + 1][k + 1] = dp[i][j][k] + 1;
                pre[i + 1][j + 1][k + 1][0] = i;
                pre[i + 1][j + 1][k + 1][1] = j;
                pre[i + 1][j + 1][k + 1][2] = k;
              }
            } else if (dp[i + 1][j + 1][to[k][s1[i + 1] - 'A']] <
                       dp[i][j][k] + 1) {
              dp[i + 1][j + 1][to[k][s1[i + 1] - 'A']] = dp[i][j][k] + 1;
              pre[i + 1][j + 1][to[k][s1[i + 1] - 'A']][0] = i;
              pre[i + 1][j + 1][to[k][s1[i + 1] - 'A']][1] = j;
              pre[i + 1][j + 1][to[k][s1[i + 1] - 'A']][2] = k;
            }
          }
        }
      }
  int M = 0, ii, jj, kk;
  for (i = 0; i <= l1; i++)
    for (j = 0; j <= l2; j++)
      for (k = 0; k < len; k++)
        if (dp[i][j][k] > M) M = dp[i][j][k], ii = i, jj = j, kk = k;
  if (M == 0) {
    puts("0");
    return 0;
  }
  char sta[105];
  int top = 0;
  while (ii >= 1 && jj >= 1) {
    int pi = pre[ii][jj][kk][0];
    int pj = pre[ii][jj][kk][1];
    int pk = pre[ii][jj][kk][2];
    if (dp[ii][jj][kk] == dp[pi][pj][pk] + 1) sta[top++] = s1[ii];
    ii = pi, jj = pj, kk = pk;
  }
  for (i = top - 1; i >= 0; i--) printf("%c", sta[i]);
  puts("");
}
