Language: C++

function Dice( faces ) {
  this.faces = faces;
  this.getFace = function ( id ) {
    return this.faces[id];
  }
  this.roll = function ( cmds ) {
    var t;
    for( var i=0; i<cmds.length; i++ ) {
      if( 'E' == cmds[i] ) {
        t = this.faces[Dice.TOP];
        this.faces[Dice.TOP] = this.faces[Dice.LEFT];
        this.faces[Dice.LEFT] = this.faces[Dice.BOTTOM];
        this.faces[Dice.BOTTOM] = this.faces[Dice.RIGHT];
        this.faces[Dice.RIGHT] = t;
      } else if( 'S' == cmds[i] ) {
        t = this.faces[Dice.TOP];
        this.faces[Dice.TOP] = this.faces[Dice.BACK];
        this.faces[Dice.BACK] = this.faces[Dice.BOTTOM];
        this.faces[Dice.BOTTOM] = this.faces[Dice.FRONT];
        this.faces[Dice.FRONT] = t;
      } else if( 'W' == cmds[i] ) {
        t = this.faces[Dice.TOP];
        this.faces[Dice.TOP] = this.faces[Dice.RIGHT];
        this.faces[Dice.RIGHT] = this.faces[Dice.BOTTOM];
        this.faces[Dice.BOTTOM] = this.faces[Dice.LEFT];
        this.faces[Dice.LEFT] = t;
      } else if( 'N' == cmds[i] ) {
        t = this.faces[Dice.TOP];
        this.faces[Dice.TOP] = this.faces[Dice.FRONT];
        this.faces[Dice.FRONT] = this.faces[Dice.BOTTOM];
        this.faces[Dice.BOTTOM] = this.faces[Dice.BACK];
        this.faces[Dice.BACK] = t;        
      } else if( 'M' == cmds[i] ) {
        t = this.faces[Dice.FRONT];
        this.faces[Dice.FRONT] = this.faces[Dice.RIGHT];
        this.faces[Dice.RIGHT] = this.faces[Dice.BACK];
        this.faces[Dice.BACK] = this.faces[Dice.LEFT];
        this.faces[Dice.LEFT] = t;        
      }
    }
  }  
}
Dice.TOP = 0;
Dice.FRONT = 1;
Dice.RIGHT = 2;
Dice.LEFT = 3;
Dice.BACK = 4;
Dice.BOTTOM = 5;

var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( '\n' );
  var output = [];
  var faces = data[0].split( ' ' ).map( Number );
  var mydice = new Dice( faces ); 
  var q = parseInt( data[1] );
  
  for( var i=0; i<q; i++ ) {
    var labels = data[2+i].split( ' ' ).map( Number );
    var cmds = "NWWWN";
    for( var j=0; j<cmds.length; j++ ) {
      if( labels[0] == mydice.getFace( Dice.TOP ) ) { break; }
      mydice.roll( cmds[j]  );
    }
    cmds = "MMM";
    for( var j=0; j<cmds.length; j++ ) {
      if( labels[1] == mydice.getFace( Dice.FRONT ) ) { break; }
      mydice.roll( cmds[j] );
    }
    output.push( mydice.getFace( Dice.RIGHT ) );
  }
  console.log( output.join( '\n' ) );
});

Compiler output:
a.cc:50:13: error: empty character constant
   50 | var input = '';
      |             ^~
a.cc:53:23: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   53 | readable.setEncoding( 'utf-8' );
      |                       ^~~~~~~
a.cc:54:14: warning: multi-character character constant [-Wmultichar]
   54 | readable.on( 'data', function( chunk ) {
      |              ^~~~~~
a.cc:58:14: warning: multi-character character constant [-Wmultichar]
   58 | readable.on( 'end', function() {
      |              ^~~~~
a.cc:1:1: error: 'function' does not name a type; did you mean 'union'?
    1 | function Dice( faces ) {
      | ^~~~~~~~
      | union
a.cc:43:1: error: 'Dice' does not name a type
   43 | Dice.TOP = 0;
      | ^~~~
a.cc:44:1: error: 'Dice' does not name a type
   44 | Dice.FRONT = 1;
      | ^~~~
a.cc:45:1: error: 'Dice' does not name a type
   45 | Dice.RIGHT = 2;
      | ^~~~
a.cc:46:1: error: 'Dice' does not name a type
   46 | Dice.LEFT = 3;
      | ^~~~
a.cc:47:1: error: 'Dice' does not name a type
   47 | Dice.BACK = 4;
      | ^~~~
a.cc:48:1: error: 'Dice' does not name a type
   48 | Dice.BOTTOM = 5;
      | ^~~~
a.cc:50:1: error: 'var' does not name a type
   50 | var input = '';
      | ^~~
a.cc:51:1: error: 'var' does not name a type
   51 | var readable = process.stdin;
      | ^~~
a.cc:52:1: error: 'readable' does not name a type
   52 | readable.resume();
      | ^~~~~~~~
a.cc:53:1: error: 'readable' does not name a type
   53 | readable.setEncoding( 'utf-8' );
      | ^~~~~~~~
a.cc:54:1: error: 'readable' does not name a type
   54 | readable.on( 'data', function( chunk ) {
      | ^~~~~~~~
a.cc:56:2: error: expected unqualified-id before ')' token
   56 | });
      |  ^
a.cc:58:1: error: 'readable' does not name a type
   58 | readable.on( 'end', function() {
      | ^~~~~~~~
a.cc:80:2: error: expected unqualified-id before ')' token
   80 | });
      |  ^