1. Abridged Problem Statement

Given a sequence of N 3D space transformations applied in order:

- T x y z: translate every point by vector (x, y, z).
- S x y z: scale coordinates independently by factors (x, y, z).
- R x y z a: rotate clockwise by a degrees about the ray from the origin through point (x, y, z).

Then given M vertices, output each vertex after all transformations are applied.

Constraints:
- 1 <= N <= 1000
- 1 <= M <= 100000
- Coordinates and parameters have absolute value at most 1000
- Rotation axis is nonzero.

2. Detailed Editorial

Key idea

Each transformation is an affine transformation in 3D. Affine transformations can be represented as 4 x 4 matrices using homogeneous coordinates. A point (x, y, z) is represented as the column vector (x, y, z, 1).

Then translation, scaling, and rotation can all be expressed as matrix multiplication. If a transformation matrix is A, then applying it to point p gives p' = A * p.

If transformations are applied in order T1, T2, ..., TN, then the final matrix is M = TN * ... * T3 * T2 * T1. The newest transformation is multiplied on the left.

So instead of applying all N transformations to all M points, which would cost O(NM), we first combine all transformations into one matrix in O(N), then apply that matrix to each point in O(M). Since matrix size is fixed 4 x 4, multiplication is constant time. Total complexity O(N + M).

Translation matrix

Translation by (tx, ty, tz):
  [1 0 0 tx]
  [0 1 0 ty]
  [0 0 1 tz]
  [0 0 0  1]
Applying this to (x, y, z, 1) gives (x + tx, y + ty, z + tz, 1).

Scaling matrix

Scaling by (sx, sy, sz):
  [sx 0  0  0]
  [0  sy 0  0]
  [0  0  sz 0]
  [0  0  0  1]
Applying this gives (sx * x, sy * y, sz * z, 1).

Rotation matrix

Rotation is around an arbitrary axis from the origin through (x, y, z). First normalize the axis: len = sqrt(x^2 + y^2 + z^2), then ux = x/len, uy = y/len, uz = z/len. Let the angle in radians be rad = angle * pi / 180.

Using Rodrigues' rotation formula, the upper-left 3 x 3 block is:
  [ c + ux²(1-c)       uxuy(1-c)-uzs    uxuz(1-c)+uys ]
  [ uyux(1-c)+uzs      c + uy²(1-c)     uyuz(1-c)-uxs ]
  [ uzux(1-c)-uys      uzuy(1-c)+uxs    c + uz²(1-c)  ]
where c = cos(angle), s = sin(angle). The full 4 x 4 rotation matrix keeps the last row and column as in the identity matrix.

Applying the final matrix

After building the final matrix M, each point (x, y, z) is transformed as:
  x' = M[0][0]*x + M[0][1]*y + M[0][2]*z + M[0][3]
  y' = M[1][0]*x + M[1][1]*y + M[1][2]*z + M[1][3]
  z' = M[2][0]*x + M[2][1]*y + M[2][2]*z + M[2][3]
The answer is printed with two digits after the decimal point.

3. C++ Solution

```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

const double PI = acos(-1.0);

namespace fastio {
constexpr int BUF_SIZE = 1 << 16;
char buf[BUF_SIZE];
int buf_pos = 0, buf_len = 0;

int get_char() {
    if(buf_pos == buf_len) {
        buf_len = (int)fread(buf, 1, BUF_SIZE, stdin);
        buf_pos = 0;
    }
    return buf_pos < buf_len ? (unsigned char)buf[buf_pos++] : EOF;
}

int skip_ws() {
    int c = get_char();
    while(c == ' ' || c == '\n' || c == '\r' || c == '\t') {
        c = get_char();
    }
    return c;
}

int read_int() {
    int c = skip_ws();
    int sign = 1;
    if(c == '-') {
        sign = -1;
        c = get_char();
    } else if(c == '+') {
        c = get_char();
    }
    int x = 0;
    while(c >= '0' && c <= '9') {
        x = x * 10 + (c - '0');
        c = get_char();
    }
    return sign * x;
}

double read_double() {
    int c = skip_ws();
    int sign = 1;
    if(c == '-') {
        sign = -1;
        c = get_char();
    } else if(c == '+') {
        c = get_char();
    }
    double x = 0.0;
    while(c >= '0' && c <= '9') {
        x = x * 10.0 + (c - '0');
        c = get_char();
    }
    if(c == '.') {
        c = get_char();
        double f = 0.1;
        while(c >= '0' && c <= '9') {
            x += (c - '0') * f;
            f *= 0.1;
            c = get_char();
        }
    }
    return sign * x;
}

char read_char() { return (char)skip_ws(); }
}  // namespace fastio

int n, m;
vector<tuple<char, array<double, 4>>> spells;
vector<array<double, 3>> points;

void read() {
    n = fastio::read_int();
    spells.assign(n, {});
    for(auto& [c, params]: spells) {
        c = fastio::read_char();
        int k = (c == 'R') ? 4 : 3;
        for(int i = 0; i < k; i++) {
            params[i] = fastio::read_double();
        }
    }

    m = fastio::read_int();
    points.assign(m, {});
    for(auto& p: points) {
        p[0] = fastio::read_double();
        p[1] = fastio::read_double();
        p[2] = fastio::read_double();
    }
}

void solve() {
    // Each basic spell is an affine map on R^3, so on the homogeneous vector
    // (x, y, z, 1) it becomes a plain linear map - a 4x4 matrix. Concretely:
    //
    //   Translation(tx,ty,tz): identity 4x4 with (tx,ty,tz) in the last column.
    //   Scaling(sx,sy,sz):     diag(sx, sy, sz, 1).
    //   Rotation(axis, angle): Rodrigues' formula in the upper-left 3x3, with
    //                          the last row and column kept as (0,0,0,1).
    //
    // Composing the whole spell list is one big 4x4 product M = T_n * ... * T_1
    // (each new spell multiplies on the left because it is applied after all
    // earlier ones), and producing the final coordinates for every vertex is
    // just M * (x, y, z, 1)^T. So we pay O(N) for the composition and O(M)
    // for the application, independently of each other.
    //
    // Translation and scaling are immediate from the definitions above - a
    // translation adds the vector to (x,y,z) and a scaling multiplies each
    // coordinate by its factor, which is exactly what the matrices encode.
    // Rotation is the interesting one because the axis is arbitrary, not one
    // of the coordinate axes. We first normalize the axis to a unit vector
    // u = (ux, uy, uz) (the input only guarantees x^2 + y^2 + z^2 > 0). Then
    // Rodrigues' formula gives the 3x3 rotation matrix R (what we drop into
    // the upper-left of t) by angle a around u as
    //
    //   R = I + sin(a) * K + (1 - cos(a)) * K^2,
    //
    // where I is the 3x3 identity and K is the cross-product matrix of u
    // (so K*v = u x v for every vector v):
    //
    //          [  0  -uz   uy ]
    //      K = [ uz    0  -ux ].
    //          [-uy   ux    0 ]
    //
    // Geometrically: any vector v splits into a part parallel to u (which is
    // fixed by the rotation) and a part perpendicular to u (which lives in
    // the plane orthogonal to u and is rotated there by angle a using the
    // 2D rotation written in the orthonormal pair (v_perp, u x v_perp));
    // expanding that gives exactly the R above. We hardcode the resulting
    // nine entries of R directly into the 3x3 block of t below to avoid
    // building K and K^2 explicitly.
    //
    // The problem says rotation is "clockwise about the ray from origin
    // through the point". Standard Rodrigues with a right-handed axis already
    // matches this when you look along the ray from the origin outward (it
    // matches the sample with R about +y by 90 sending (1,0,0) to (0,0,-1)).

    auto id = []() {
        array<array<double, 4>, 4> r{};
        for(int i = 0; i < 4; i++) {
            r[i][i] = 1.0;
        }
        return r;
    };

    auto mul = [](const array<array<double, 4>, 4>& a,
                  const array<array<double, 4>, 4>& b) {
        array<array<double, 4>, 4> r{};
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 4; j++) {
                double s = 0.0;
                for(int k = 0; k < 4; k++) {
                    s += a[i][k] * b[k][j];
                }
                r[i][j] = s;
            }
        }
        return r;
    };

    auto M = id();
    for(auto& [c, p]: spells) {
        auto t = id();
        if(c == 'T') {
            t[0][3] = p[0];
            t[1][3] = p[1];
            t[2][3] = p[2];
        } else if(c == 'S') {
            t[0][0] = p[0];
            t[1][1] = p[1];
            t[2][2] = p[2];
        } else {
            double x = p[0], y = p[1], z = p[2];
            double len = sqrt(x * x + y * y + z * z);
            x /= len;
            y /= len;
            z /= len;

            double rad = p[3] * PI / 180.0;
            double co = cos(rad), si = sin(rad);
            t[0][0] = co + x * x * (1 - co);
            t[0][1] = x * y * (1 - co) - z * si;
            t[0][2] = x * z * (1 - co) + y * si;
            t[1][0] = y * x * (1 - co) + z * si;
            t[1][1] = co + y * y * (1 - co);
            t[1][2] = y * z * (1 - co) - x * si;
            t[2][0] = z * x * (1 - co) - y * si;
            t[2][1] = z * y * (1 - co) + x * si;
            t[2][2] = co + z * z * (1 - co);
        }

        M = mul(t, M);
    }

    cout << fixed << setprecision(2);
    for(auto& v: points) {
        double x = M[0][0] * v[0] + M[0][1] * v[1] + M[0][2] * v[2] + M[0][3];
        double y = M[1][0] * v[0] + M[1][1] * v[1] + M[1][2] * v[2] + M[1][3];
        double z = M[2][0] * v[0] + M[2][1] * v[1] + M[2][2] * v[2] + M[2][3];
        cout << x << ' ' << y << ' ' << z << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        solve();
    }

    return 0;
}
```

4. Python Solution

```python
import sys
import math


def identity_matrix():
    """
    Create and return a 4x4 identity matrix.
    """
    # Start with a 4x4 zero matrix.
    mat = [[0.0] * 4 for _ in range(4)]

    # Put 1.0 on the main diagonal.
    for i in range(4):
        mat[i][i] = 1.0

    return mat


def multiply(a, b):
    """
    Multiply two 4x4 matrices.

    Returns:
        a * b
    """
    # Result matrix initialized with zeros.
    res = [[0.0] * 4 for _ in range(4)]

    # Standard matrix multiplication.
    for i in range(4):
        for j in range(4):
            s = 0.0
            for k in range(4):
                s += a[i][k] * b[k][j]
            res[i][j] = s

    return res


def main():
    # Read all input tokens at once.
    # This is fast enough for 100000 points.
    data = sys.stdin.buffer.read().split()

    # Token pointer.
    idx = 0

    # Read number of transformations.
    n = int(data[idx])
    idx += 1

    # Combined transformation matrix.
    # Initially it does nothing.
    final = identity_matrix()

    # Process each spell in order.
    for _ in range(n):
        # Spell type: b'T', b'S', or b'R'.
        typ = data[idx].decode()
        idx += 1

        # Matrix of the current transformation.
        cur = identity_matrix()

        if typ == 'T':
            # Translation has three parameters.
            tx = float(data[idx])
            ty = float(data[idx + 1])
            tz = float(data[idx + 2])
            idx += 3

            # Translation values are placed in the last column.
            cur[0][3] = tx
            cur[1][3] = ty
            cur[2][3] = tz

        elif typ == 'S':
            # Scaling has three parameters.
            sx = float(data[idx])
            sy = float(data[idx + 1])
            sz = float(data[idx + 2])
            idx += 3

            # Scaling factors are placed on the diagonal.
            cur[0][0] = sx
            cur[1][1] = sy
            cur[2][2] = sz

        else:
            # Rotation has four parameters:
            # axis point x, y, z and angle in degrees.
            x = float(data[idx])
            y = float(data[idx + 1])
            z = float(data[idx + 2])
            angle = float(data[idx + 3])
            idx += 4

            # Normalize the axis vector.
            length = math.sqrt(x * x + y * y + z * z)
            x /= length
            y /= length
            z /= length

            # Convert degrees to radians.
            rad = angle * math.pi / 180.0

            # Precompute cosine and sine.
            co = math.cos(rad)
            si = math.sin(rad)

            # Common value used in Rodrigues' formula.
            one_minus_co = 1.0 - co

            # Fill the upper-left 3x3 part with Rodrigues' rotation matrix.
            cur[0][0] = co + x * x * one_minus_co
            cur[0][1] = x * y * one_minus_co - z * si
            cur[0][2] = x * z * one_minus_co + y * si

            cur[1][0] = y * x * one_minus_co + z * si
            cur[1][1] = co + y * y * one_minus_co
            cur[1][2] = y * z * one_minus_co - x * si

            cur[2][0] = z * x * one_minus_co - y * si
            cur[2][1] = z * y * one_minus_co + x * si
            cur[2][2] = co + z * z * one_minus_co

        # Compose transformations.
        # If current spell is applied after previous spells:
        #
        #   new_final = cur * final
        #
        # because points are column vectors.
        final = multiply(cur, final)

    # Read number of points.
    m = int(data[idx])
    idx += 1

    # Prepare output lines.
    out = []

    # Apply final transformation to every point.
    for _ in range(m):
        # Read point coordinates.
        px = float(data[idx])
        py = float(data[idx + 1])
        pz = float(data[idx + 2])
        idx += 3

        # Multiply final matrix by homogeneous point vector [px, py, pz, 1].
        x = final[0][0] * px + final[0][1] * py + final[0][2] * pz + final[0][3]
        y = final[1][0] * px + final[1][1] * py + final[1][2] * pz + final[1][3]
        z = final[2][0] * px + final[2][1] * py + final[2][2] * pz + final[2][3]

        # Avoid printing "-0.00" for tiny floating-point noise.
        if abs(x) < 0.0005:
            x = 0.0
        if abs(y) < 0.0005:
            y = 0.0
        if abs(z) < 0.0005:
            z = 0.0

        # Print with two digits after the decimal point.
        out.append(f"{x:.2f} {y:.2f} {z:.2f}")

    # Write all output at once.
    sys.stdout.write("\n".join(out))


if __name__ == "__main__":
    main()
```

5. Compressed Editorial

Represent every point as a homogeneous vector (x, y, z, 1). Then every spell is a 4 x 4 matrix:
- Translation: identity with translation vector in the last column.
- Scaling: diagonal matrix.
- Rotation: Rodrigues' formula in the upper-left 3 x 3 block.

If spells are applied in input order, and points are column vectors, compose as M = current_spell_matrix * M. After all spells, transform every vertex once: p' = M * p.

Rotation uses normalized axis (x, y, z) and angle in radians. Its matrix is:
  [ c+x²(1-c)   xy(1-c)-zs   xz(1-c)+ys ]
  [ yx(1-c)+zs  c+y²(1-c)    yz(1-c)-xs ]
  [ zx(1-c)-ys  zy(1-c)+xs   c+z²(1-c)  ]
where c = cos(angle), s = sin(angle).

Complexity O(N + M) because matrix size is constant.
