#include <bits/stdc++.h>
#include <chrono>
using namespace std;

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

struct _dice {
    _i64 pip1, pip2, pip3, pip4, pip5, pip6;
    void pipget() { cin >> pip1 >> pip2 >> pip3 >> pip4 >> pip5 >> pip6; }
    void move(string order) {
        _i64 _pip1, _pip2, _pip3, _pip4, _pip5, _pip6;
        _foreach(e, order) {
            _pip1 = pip1; _pip2 = pip2; _pip3 = pip3; _pip4 = pip4; _pip5 = pip5; _pip6 = pip6;
            switch(e) {
                case 'E': pip1 = _pip4; pip3 = _pip1; pip6 = _pip3; pip4 = _pip6; break;
                case 'N': pip1 = _pip2; pip2 = _pip6; pip6 = _pip5; pip5 = _pip1; break;
                case 'S': pip1 = _pip5; pip2 = _pip1; pip6 = _pip2; pip5 = _pip6; break;
                case 'W': pip1 = _pip3; pip3 = _pip6; pip6 = _pip4; pip4 = _pip1; break;
            }
        }
    }
    void rotate(string order) {
        _i64 _pip1, _pip2, _pip3, _pip4, _pip5, _pip6;
        _foreach(e, order) {
            _pip1 = pip1; _pip2 = pip2; _pip3 = pip3; _pip4 = pip4; _pip5 = pip5; _pip6 = pip6;
            switch(e) {
                case 'C': pip2 = _pip3; pip3 = _pip5; pip5 = _pip4; pip4 = _pip2; break;
                case 'A': pip2 = _pip4; pip3 = _pip2; pip5 = _pip3; pip4 = _pip5; break;
            }
        }
    }
    void decide(_i64 label1, _i64 info1, _i64 label2, _i64 info2) {
        _i64 _pip1, _pip2, _pip3, _pip4, _pip5, _pip6;
        _rep(i, 13) {
            switch(i) {
                case 0: break;
                case 1: move("N"); break;
                case 2: move("N"); break;
                case 3: move("N"); break;
                case 4: move("N"); break;
                case 5: move("E"); break;
                case 6: move("E"); break;
                case 7: move("E"); break;
                case 8: move("E"); break;
                case 9: rotate("C"); break;
                case 10: rotate("C"); break;
                case 11: rotate("C"); break;
                case 12: rotate("C"); break;
            }
            if(pipinfo(label1) == info1) { break; }
        }
        if(label1 == 1 || label1 == 6) {
            _rep(i, 4) {
                switch(i) {
                    case 0: break;
                    case 1: rotate("C"); break;
                    case 2: rotate("C"); break;
                    case 3: rotate("C"); break;
                }
                if(pipinfo(label2) == info2) { break; }
            }
        }
        else if(label1 == 2 || label1 == 5) {
            _rep(i, 4) {
                switch(i) {
                    case 0: break;
                    case 1: move("E"); break;
                    case 2: move("E"); break;
                    case 3: move("E"); break;
                }
                if(pipinfo(label2) == info2) { break; }
            }
        }
        else if(label1 == 3 || label1 == 4) {
            _rep(i, 4) {
                switch(i) {
                    case 0: break;
                    case 1: move("N"); break;
                    case 2: move("N"); break;
                    case 3: move("N"); break;
                }
                if(pipinfo(label2) == info2) { break; }
            }
        }
    }
    bool operator==(const _dice &dice) const {
        _dice copy = dice;
        copy.decide(1, pip1, 2, pip2);
        bool flag1 = pip1 == copy.pip1;
        bool flag2 = pip2 == copy.pip2;
        bool flag3 = pip3 == copy.pip3;
        bool flag4 = pip4 == copy.pip4;
        bool flag5 = pip5 == copy.pip5;
        bool flag6 = pip6 == copy.pip6;
        return flag1 && flag2 && flag3 && flag4 && flag5 && flag6;
    }
    private:
    _i64 pipinfo(_i64 number) {
        switch(number) {
            case 1: return pip1; case 2: return pip2; case 3: return pip3;
            case 4: return pip4; case 5: return pip5; case 6: return pip6;
        }
    }
};

int main() {
    {
        _time time(disable);
        _dice dice; string order;
        dice.pipget(); cin >> order;
        dice.move(order);
        cout << dice.pip1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3228