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

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

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

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

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

a.x = m
a.q = d
a.u = i
a.p = i
i.q = f
i.o = f
i.v = f
i.z = a
m.q = d
m.o = i
f.z = i
f.q = d
d.x = m
d.q = a
d.u = i
d.p = i
assert m.o.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.q: A = None
        self.u: B = None
        self.p: B = None
        self.txt = txt

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

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

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

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

a.x = m
a.q = d
a.u = i
a.p = i
i.q = f
i.o = f
i.v = f
i.z = a
m.q = d
m.o = i
f.z = i
f.q = d
d.x = m
d.q = a
d.u = i
d.p = i
assert m.o.z.q.txt == "d"