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

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

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

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

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

i.y = n
i.q = a
i.r = m
m.r = n
m.p = n
m.x = d
m.q = g
d.z = a
d.x = g
n.w = a
n.v = i
n.x = g
n.o = d
a.w = n
a.v = i
a.x = d
a.o = d
g.z = a
g.x = d
assert m.x.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.q: D = None
        self.r: B = None
        self.txt = txt

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

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

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

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

i.y = n
i.q = a
i.r = m
m.r = n
m.p = n
m.x = d
m.q = g
d.z = a
d.x = g
n.w = a
n.v = i
n.x = g
n.o = d
a.w = n
a.v = i
a.x = d
a.o = d
g.z = a
g.x = d
assert m.x.z.o.txt == "d"