#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

// ???????????¢?????????
class DiceSurface
{
private:
	unsigned short	number_;	// ????????¢??????????????????

public:
	DiceSurface() {}
	DiceSurface(const unsigned short& number)
		: number_(number)
	{}

	~DiceSurface() {}

	// ?????????
	void setNumber(const unsigned short& number) { number_ = number; }
	// ?????????
	unsigned short getNumber() const { return number_; }

};


class Dice
{
private:
	const DiceSurface* top_;	// ?????¢
	const DiceSurface* north_;	// ?????¢
	const DiceSurface* south_;	// ?????¢
	const DiceSurface* east_; 	// ??±??¢
	const DiceSurface* west_; 	// ?\???¢
	const DiceSurface* bottom_;	// ?????¢

private:
	Dice() {}

public:
	Dice( const unsigned short& topNumber
		, const unsigned short& northNumber
		, const unsigned short& southNumber
		, const unsigned short& eastNumber
		, const unsigned short& westNumber
		, const unsigned short& bottomNumber )
	{
		top_	= new DiceSurface(topNumber);
		north_	= new DiceSurface(northNumber);
		south_	= new DiceSurface(southNumber);
		east_	= new DiceSurface(eastNumber);
		west_	= new DiceSurface(westNumber);
		bottom_	= new DiceSurface(bottomNumber);
	}

	~Dice() {
		delete top_;		
		delete north_;
		delete south_;
		delete east_; 
		delete west_; 
		delete bottom_;
	}

	unsigned short getTopNumber() {
		return top_->getNumber();
	}

	void rotateNorth() {
		const DiceSurface* tmp = top_;
		top_	= south_;
		south_	= bottom_;
		bottom_	= north_;
		north_	= tmp;
	}

	void rotateSouth() {
		const DiceSurface* tmp = top_;
		top_	= north_;
		north_	= bottom_;
		bottom_	= south_;
		south_	= tmp;
	}

	void rotateEast() {
		const DiceSurface* tmp = top_;
		top_	= west_;
		west_	= bottom_;
		bottom_	= east_;
		east_	= tmp;
	}

	void rotateWest() {
		const DiceSurface* tmp = top_;
		top_	= east_;
		east_	= bottom_;
		bottom_ = west_;
		west_	= tmp;
	}

	void rotateClockwise() {
		const DiceSurface* tmp = north_;
		north_	= west_;
		west_	= south_;
		south_	= east_;
		east_	= tmp;
	}

	void rotateAnticlockwise() {
		const DiceSurface* tmp = north_;
		north_	= east_;
		east_	= south_;
		south_	= west_;
		west_	= tmp;
	}
};

int main(int, char**)
{
	const unsigned short surfaceSize = 6;
	int numbers[surfaceSize];
	for ( int i = 0; i < surfaceSize; ++i) {
		cin >> numbers[i];
	}

	Dice dice(numbers[0]	// ?????¢
			, numbers[4]	// ?????¢
			, numbers[1]	// ?????¢
			, numbers[2]	// ??±??¢
			, numbers[3]	// ?\???¢
			, numbers[5]);	// ?????¢

	string commands;
	cin >> commands;
	for ( unsigned int i = 0; i < commands.size(); ++i ) {
		char& command  = commands[i];
		if ( command == 'N' ) {
			dice.rotateNorth();
		} else if ( command == 'S' ) {
			dice.rotateSouth();
		} else if ( command == 'E' ) {
			dice.rotateEast();
		} else if ( command == 'W' ) {
			dice.rotateWest();
		}
	}
	
	cout << dice.getTopNumber() << endl;

	return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
char s[305];
int len, n, K, a[305], f[305][305][305];
int main() {
	scanf("%s %d", s + 1, &K);
	len = strlen(s + 1);
	n = 0;
	for (int i = 1, lst = 0; i <= len + 1; i++) {
		if (i == len + 1 || s[i] == '0') {
			a[++n] = i - lst - 1;
			lst = i;
		}
	}
	reverse(a + 1, a + 1 + n);
	f[0][0][0] = 1;
	int ps = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= ps; j++) {
			for (int k = 0; k <= ps; k++) if (f[i - 1][j][k]) {
				for (int l = 0; l <= a[i]; l++) {
					Add(f[i][j + a[i] - l][k + a[i] - l], f[i - 1][j][k]);
				}
			}
		}
		for (int k = 0; k <= ps; k++) {
			int sum = 0;
			for (int j = ps; j >= 0; j--) {
				Add(f[i][j][k], sum);
				Add(sum, f[i - 1][j][k]);
			}
		}
		ps += a[i];
	}
	int ans = 0;
	for (int k = 0; k <= min(K, ps); k++) {
		Add(ans, f[n][0][k]);
	}
	printf("%d\n", ans);
	return 0;
}