3D rotation of an object with respect to another object's rotation

I am writing a python code to translate and rotate an object with respect to another object. Please take a look at the picture bellow: The smiley face and the arrow have initial poses (position and orientation) as shown in the left picture. Then, the face rotates. I want the arrow to rotate and move to the pose shown on the right picture. I can imagine how to do that in 2D. However, I found it difficult to extend it to 3D.

So, the problem is as follows: Given the initial and the current 3D pose of object x (say face) and the initial pose of object y (arrow), find a transformation T such that if we transform the initial pose of y using T, objects x and y keep their initial pose with respect to each other when the pose of object x changes.

The poses I get are quaternions, However, I have a python library which I can use to convert them to Euler angles and rotation matrices (and vice versa), so, that is not a problem.

y'_position = (x'_position - x_position)