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

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

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

g = A("g")
f = B("f")
d = C("d")
h = B("h")

g.r = h
f.w = g
f.q = g
f.z = d
d.x = g
h.w = g
h.q = g
h.z = d
assert h.z.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

g = A("g")
f = B("f")
d = C("d")
h = B("h")

g.r = h
f.w = g
f.q = g
f.z = d
d.x = g
h.w = g
h.q = g
h.z = d
assert h.z.x.r.txt == "h"