#include<iostream>
#include<vector>
#include<iomanip>
#include<math.h>

using namespace std;

void ulaz(vector<int> &a, vector<int> &b, int &c, int &n, int &m);

int main(){
    vector<int> a;
    vector<int> b;
    int c;
    int n;
    int m;
    ulaz(a, b, c, n, m);

    for(int i=1;i<a.size();i++){
        cout << setw(3) << a.at(i) << " ";
    }

    cout<<endl;

    for(int i=0;i<=n-m;i++){
        for(int j=1;j<=m;j++){
            if(i+b[j] > a.size()){
                a.resize(i+b[j]);
            }
            a[i + b[j]] = a[i+j];
        }
    }


    for(int i=1;i<a.size();i++){
        cout << setw(3) << a.at(i) << " ";
    }
    int kc = c;
    __int64 s = 0;
    for(int i=1;i<=n;i++){
        s+=c*a[i];
        c*=kc;
        s%=998244353;
    }
    cout << endl;
    cout << s << endl;
    return 0;
}

void ulaz(vector<int> &a, vector<int> &b, int &c, int &n, int &m){
    cin >> n >> m;
    a.resize(n+1);
    b.resize(m+1);
    for(int i=1;i<=n;i++){
        a.at(i) = i;
    }

    for(int i=1;i<=m;i++){
        cin >> b.at(i);
    }

    cin >> c;
}