#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
const long long N = 105;
string S1, S2, S3;
long long n1, n2, n3, Point[26], Kmp[N], Next1[N][26], Next2[N][26],
    Dp[N][N][N];
pair<pair<long long, long long>, pair<long long, long long> > Pre[N][N][N];
vector<long long> Out;
void Input() {
  cin >> S1 >> S2 >> S3;
  n1 = S1.size(), n2 = S2.size(), n3 = S3.size();
  S1 = ' ' + S1, S2 = ' ' + S2, S3 = ' ' + S3;
}
void Build_Kmp() {
  long long Cur = 0;
  Kmp[1] = 0;
  for (long long i = 1; i < n3; ++i) {
    while (Cur && S3[i + 1] != S3[Cur + 1]) Cur = Kmp[Cur];
    if (S3[i + 1] == S3[Cur + 1]) Kmp[i + 1] = ++Cur;
  }
}
void Prepare() {
  for (long long j = 0; j <= 25; ++j) Point[j] = n1 + 1;
  for (long long i = n1; i >= 0; --i) {
    for (long long j = 0; j <= 25; ++j) Next1[i][j] = Point[j];
    if (i) Point[S1[i] - 'A'] = i;
  }
  for (long long j = 0; j <= 25; ++j) Point[j] = n2 + 1;
  for (long long i = n2; i >= 0; --i) {
    for (long long j = 0; j <= 25; ++j) Next2[i][j] = Point[j];
    if (i) Point[S2[i] - 'A'] = i;
  }
}
void Solve() {
  Build_Kmp();
  Prepare();
  memset(Dp, -1, sizeof Dp);
  Dp[0][0][0] = 0;
  long long Res = 0;
  pair<pair<long long, long long>, long long> Pos = {{0, 0}, 0};
  for (long long i = 0; i <= n1; ++i) {
    for (long long j = 0; j <= n2; ++j) {
      for (long long Cur = 0; Cur < n3; ++Cur) {
        if (Dp[i][j][Cur] == -1) continue;
        if (Dp[i][j][Cur] > Res) {
          Res = Dp[i][j][Cur];
          Pos = {{i, j}, Cur};
        }
        for (long long Dig = 0; Dig <= 25; ++Dig) {
          long long newCur = Cur;
          while (newCur && S3[newCur + 1] - 'A' != Dig) newCur = Kmp[newCur];
          if (S3[newCur + 1] - 'A' == Dig) newCur++;
          if (newCur == n3) continue;
          long long newi = Next1[i][Dig], newj = Next2[j][Dig];
          if (Dp[newi][newj][newCur] < Dp[i][j][Cur] + 1) {
            Dp[newi][newj][newCur] = Dp[i][j][Cur] + 1;
            Pre[newi][newj][newCur] = {{Dig, Cur}, {i, j}};
          }
        }
      }
    }
  }
  if (Res == 0) {
    cout << 0;
    return;
  }
  while (Pos.first.first && Pos.first.second) {
    long long i = Pos.first.first, j = Pos.first.second, Cur = Pos.second;
    Out.push_back(Pre[i][j][Cur].first.first);
    Pos.second = Pre[i][j][Cur].first.second;
    Pos.first.first = Pre[i][j][Cur].second.first;
    Pos.first.second = Pre[i][j][Cur].second.second;
  }
  reverse((Out).begin(), (Out).end());
  for (auto i : Out) cout << char(i + 'A');
}
int main() {
  if (fopen("trash.inp", "r"))
    freopen("trash.inp", "r", stdin), freopen("trash.out", "w", stdout);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Input();
  Solve();
}
