#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int table_4[24][4],index_8,leftTable[24],rightTable[24],m_data[8] = {0,1,2,3,4,5,6,7};
int* table_8;

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

void calc8(){

	int select_num = 4,num,loc_left[4],loc_right[4],left_index,right_index,index,calc[4],value;

	index_8 = 0;

	for(int i = 0; i < 256;i++){
		num = 0;
		for(int k = 0; k < 8; k++){
			if(i & (1 << k))num++;
		}
		if(num != select_num)continue;

		left_index = right_index = 0;

		for(int k = 0; k < 8; k++){
			if(i & (1 << k)){
				loc_left[left_index++] = k;
			}else{
				loc_right[right_index++] = k;
			}
		}

		left_index = right_index = 0;

		calc[0] = m_data[loc_left[0]],calc[1] = m_data[loc_left[1]],calc[2] = m_data[loc_left[2]],calc[3] = m_data[loc_left[3]];

		for(index = 0;index < 24; index++){
			value = 0;
			for(int p = 0; p < 4;p++){
				value = 10*value + calc[table_4[index][p]];
			}
			leftTable[left_index++] = value;
		}

		calc[0] = m_data[loc_right[0]],calc[1] = m_data[loc_right[1]],calc[2] = m_data[loc_right[2]],calc[3] = m_data[loc_right[3]];

		for(index = 0;index < 24; index++){
			value = 0;
			for(int p = 0; p < 4;p++){
				value = 10*value + calc[table_4[index][p]];
			}
			rightTable[right_index++] = value;
		}

		for(int k = 0; k < 24; k++){
			for(int p = 0; p < 24; p++){
				table_8[index_8++] = 10000*leftTable[k] + rightTable[p];
			}
		}
	}
}


int main(){

	table_8 = new int[40320];

	int index_4 = 0;

	for(int a = 0; a < 4; a++){
		for(int b = 0; b < 4; b++){
			for(int c = 0; c < 4; c++){
				for(int d = 0; d < 4; d++){
					if(a != b && a != c && a != d && b != c && b != d && c != d){
						table_4[index_4][0] = a,table_4[index_4][1] = b,table_4[index_4][2] = c,table_4[index_4][3] = d;
						index_4++;
					}
				}
			}
		}
	}

	calc8();

	int DIV = 10,line;

	int **calc_table = new int*[40320];
	for(int i = 0; i < 40320; i++){
		calc_table[i] = new int[8];
		line = table_8[i];
		for(int k = 0; k < 8; k++){
			calc_table[i][7-k] = line%DIV;
			line /= DIV;
		}
	}

	char colors[8][21],buf[21],all_color[200],work[8][21],tmp_work[8][21];
	int array[24][8] = {{0,1,2,3,4,5,6,7},
						{7,6,5,4,3,2,1,0},
						{3,0,1,2,7,4,5,6},
						{6,5,4,7,2,1,0,3},
						{2,3,0,1,6,7,4,5},
						{5,4,7,6,1,0,3,2},
						{1,2,3,0,5,6,7,4},
						{4,7,6,5,0,3,2,1},

						{7,3,2,6,4,0,1,5},
						{5,1,0,4,6,2,3,7},
						{6,7,3,2,5,4,0,1},
						{1,0,4,5,2,3,7,6},
						{2,6,7,3,1,5,4,0},
						{0,4,5,1,3,7,6,2},
						{3,2,6,7,0,1,5,4},
						{4,5,1,0,7,6,2,3},


						{7,4,0,3,6,5,1,2},
						{2,1,5,6,3,0,4,7},
						{3,7,4,0,2,6,5,1},
						{1,5,6,2,0,4,7,3},
						{0,3,7,4,1,2,6,5},
						{5,6,2,1,4,7,3,0},
						{4,0,3,7,5,1,2,6},
						{6,2,1,5,7,3,0,4}
						};

	set<string> S;

	bool FLG;

	int index,ans;

	while(scanf("%s",buf) != EOF){
		strcpy(colors[0],buf);
		for(int i = 1; i <= 7; i++){
			scanf("%s",colors[i]);
		}

		S.clear();

		index = 0;

		for(int i = 0; i < 8; i++){
			for(int k = 0; colors[i][k] != '\0'; k++){
				all_color[index++] = colors[i][k];
			}
		}
		all_color[index] = '\0';

		S.insert(string(all_color));

		ans = 1;

		for(int i = 0; i < 40320; i++){

			for(int k = 0; k < 8; k++){
				strcpy(work[k],colors[calc_table[i][k]]);
			}

			FLG = true;

			for(int a = 0;a < 24; a++){
				for(int b = 0; b < 8; b++){
					strcpy(tmp_work[b],work[array[a][b]]);
				}
				index = 0;
				for(int b = 0; b < 8; b++){
					for(int c = 0; tmp_work[b][c] != '\0'; c++){
						all_color[index++] = tmp_work[b][c];
					}
				}
				all_color[index] = '\0';

				if(S.count(string(all_color)) != 0){
					FLG = false;
					break;
				}
			}

			if(FLG){
				S.insert(string(all_color));
				ans++;
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 5496