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

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

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

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

d = A("d")
i = B("i")
a = C("a")
f = D("f")
e = D("e")
g = C("g")
c = C("c")
b = C("b")
n = A("n")
m = C("m")

d.z = i
d.q = e
d.r = n
i.y = a
a.r = i
f.o = d
e.o = d
g.r = i
c.r = i
b.r = i
n.z = i
n.q = e
n.r = d
m.r = i
assert n.q.o.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.q: D = None
        self.r: A = None
        self.txt = txt

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

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

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

d = A("d")
i = B("i")
a = C("a")
f = D("f")
e = D("e")
g = C("g")
c = C("c")
b = C("b")
n = A("n")
m = C("m")

d.z = i
d.q = e
d.r = n
i.y = a
a.r = i
f.o = d
e.o = d
g.r = i
c.r = i
b.r = i
n.z = i
n.q = e
n.r = d
m.r = i
assert n.q.o.z.y.txt == "a"