class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

c = A("c")
b = B("b")
j = C("j")
m = B("m")

c.r = j
b.x = c
b.w = j
b.p = j
j.o = m
m.x = c
m.w = j
m.p = j
assert m.x.r.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

c = A("c")
b = B("b")
j = C("j")
m = B("m")

c.r = j
b.x = c
b.w = j
b.p = j
j.o = m
m.x = c
m.w = j
m.p = j
assert m.x.r.o.p.txt == "j"