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

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

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

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

j = A("j")
a = B("a")
k = C("k")
f = D("f")
c = C("c")
d = A("d")

j.q = a
j.w = f
j.z = f
a.p = c
a.s = c
a.o = f
k.o = d
k.q = j
f.z = k
c.o = j
c.q = d
d.q = a
d.w = f
d.z = f
assert f.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.w: D = None
        self.z: D = None
        self.txt = txt

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

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

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

j = A("j")
a = B("a")
k = C("k")
f = D("f")
c = C("c")
d = A("d")

j.q = a
j.w = f
j.z = f
a.p = c
a.s = c
a.o = f
k.o = d
k.q = j
f.z = k
c.o = j
c.q = d
d.q = a
d.w = f
d.z = f
assert f.z.q.z.txt == "f"