Language: C++

#include <algorithm>
#include <array>
#include <iostream>
#include <iterator>
#include <sstream>

class Dice {
 private:
  std::array<int, 6> inner_;

 public:
  Dice(std::string str) {
    std::istringstream stream(str);
    for(int i = 0; i != 6; ++i) {
      stream >> inner_[i];
    }
  }

  void roll(char dir) {
    std::array<int, 6> new_dice;
    switch(dir) {
    case 'N':
      new_dice[0] = inner_[1];
      new_dice[1] = inner_[5];
      new_dice[2] = inner_[2];
      new_dice[3] = inner_[3];
      new_dice[4] = inner_[0];
      new_dice[5] = inner_[4];
      break;
    case 'S':
      new_dice[0] = inner_[4];
      new_dice[1] = inner_[0];
      new_dice[2] = inner_[2];
      new_dice[3] = inner_[3];
      new_dice[4] = inner_[5];
      new_dice[5] = inner_[1];
      break;
    case 'W':
      new_dice[0] = inner_[2];
      new_dice[1] = inner_[1];
      new_dice[2] = inner_[5];
      new_dice[3] = inner_[0];
      new_dice[4] = inner_[4];
      new_dice[5] = inner_[3];
      break;
    case 'E':
      new_dice[0] = inner_[3];
      new_dice[1] = inner_[1];
      new_dice[2] = inner_[0];
      new_dice[3] = inner_[5];
      new_dice[4] = inner_[4];
      new_dice[5] = inner_[2];
      break;
    }
    inner_ = new_dice;
  }

  int get(int i) {
    return inner_.at(i);
  }

  std::size_t index(int x) {
    auto it = std::find(inner_.begin(), inner_.end(), x);
    return std::distance(inner_.begin(), it);
  }

  int right_side(int top, int front) {
    auto t = index(top);
    auto f = index(front);
    auto side = 3 - std::min(t, 5 - t) - std::min(f, 5 - f);
    auto cnt = 0;
    if(t > 5 - t)
      cnt++;
    if(f > 5 - f)
      cnt++;
    return get(cnt % 2 == 0 ? side : 5 - side);
  }
}

  int f(bool cond, int side) {
  return dice(cond ? side : 5 - side);
}

friend std::ostream &operator<<(std::ostream &out, const Dice &dice) {
  for(int i = 0; i != 5; ++i) {
    out << dice.inner_.at(i) << " ";
  }
  out << dice.inner_.at(5);
  return out;
}
}
;

int main() {
  std::string line;
  std::getline(std::cin, line);
  Dice dice(line);

  int n;
  std::getline(std::cin, line);
  std::istringstream stream(line);
  stream >> n;

  for(int i = 0; i != n; ++i) {
    std::getline(std::cin, line);
    int a, b;
    std::istringstream stream(line);
    stream >> a >> b;
    std::cout << dice.right_side(a, b) << std::endl;
  }
  return 0;
}

Compiler output:
a.cc:78:2: error: expected ';' after class definition
   78 | }
      |  ^
      |  ;
a.cc: In function 'int f(bool, int)':
a.cc:81:10: error: 'dice' was not declared in this scope; did you mean 'Dice'?
   81 |   return dice(cond ? side : 5 - side);
      |          ^~~~
      |          Dice
a.cc: At global scope:
a.cc:84:1: error: 'friend' used outside of class
   84 | friend std::ostream &operator<<(std::ostream &out, const Dice &dice) {
      | ^~~~~~
      | ------
a.cc: In function 'std::ostream& operator<<(std::ostream&, const Dice&)':
a.cc:86:17: error: 'std::array<int, 6> Dice::inner_' is private within this context
   86 |     out << dice.inner_.at(i) << " ";
      |                 ^~~~~~
a.cc:9:22: note: declared private here
    9 |   std::array<int, 6> inner_;
      |                      ^~~~~~
a.cc:88:15: error: 'std::array<int, 6> Dice::inner_' is private within this context
   88 |   out << dice.inner_.at(5);
      |               ^~~~~~
a.cc:9:22: note: declared private here
    9 |   std::array<int, 6> inner_;
      |                      ^~~~~~
a.cc: At global scope:
a.cc:91:1: error: expected declaration before '}' token
   91 | }
      | ^