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

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: D = None
        self.txt = txt

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

a = A("a")
f = B("f")
m = C("m")
g = D("g")

a.o = m
a.z = m
a.x = f
f.r = g
f.s = g
m.q = f
m.t = g
g.p = a
g.z = m
g.w = m
assert a.x.s.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.z: C = None
        self.x: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: D = None
        self.txt = txt

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

a = A("a")
f = B("f")
m = C("m")
g = D("g")

a.o = m
a.z = m
a.x = f
f.r = g
f.s = g
m.q = f
m.t = g
g.p = a
g.z = m
g.w = m
assert a.x.s.w.q.txt == "f"