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

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

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

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

f = A("f")
d = B("d")
a = C("a")
h = D("h")
m = C("m")
k = B("k")

f.x = h
f.z = k
d.r = k
d.o = h
d.t = f
d.q = f
a.y = m
a.q = h
h.w = a
m.y = a
m.q = h
k.r = d
k.o = h
k.t = f
k.q = f
assert f.x.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.z: B = None
        self.txt = txt

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

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

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

f = A("f")
d = B("d")
a = C("a")
h = D("h")
m = C("m")
k = B("k")

f.x = h
f.z = k
d.r = k
d.o = h
d.t = f
d.q = f
a.y = m
a.q = h
h.w = a
m.y = a
m.q = h
k.r = d
k.o = h
k.t = f
k.q = f
assert f.x.w.y.txt == "m"