class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: A = None
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.w: C = None
        self.p: C = None
        self.o: C = None
        self.txt = txt

e = A("e")
f = B("f")
b = C("b")
m = C("m")
n = A("n")

e.r = f
e.x = f
e.y = n
f.x = b
b.w = m
b.p = m
b.o = m
m.w = b
m.p = b
m.o = b
n.r = f
n.x = f
n.y = e
assert n.x.x.w.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.y: A = None
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.w: C = None
        self.p: C = None
        self.o: C = None
        self.txt = txt

e = A("e")
f = B("f")
b = C("b")
m = C("m")
n = A("n")

e.r = f
e.x = f
e.y = n
f.x = b
b.w = m
b.p = m
b.o = m
m.w = b
m.p = b
m.o = b
n.r = f
n.x = f
n.y = e
assert n.x.x.w.p.w.txt == "m"