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

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

class C:
    def __init__(self, txt: str):
        self.r: C = None
        self.t: D = None
        self.v: A = None
        self.txt = txt

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

d = A("d")
a = B("a")
g = C("g")
b = D("b")
h = C("h")
m = B("m")
c = A("c")
k = B("k")
i = C("i")

d.z = b
a.x = k
a.t = b
a.s = b
a.z = h
g.r = i
g.t = b
g.v = c
b.q = d
h.r = g
h.t = b
h.v = d
m.x = k
m.t = b
m.s = b
m.z = g
c.z = b
k.x = m
k.t = b
k.s = b
k.z = g
i.r = g
i.t = b
i.v = c
assert i.r.r.v.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.r: C = None
        self.t: D = None
        self.v: A = None
        self.txt = txt

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

d = A("d")
a = B("a")
g = C("g")
b = D("b")
h = C("h")
m = B("m")
c = A("c")
k = B("k")
i = C("i")

d.z = b
a.x = k
a.t = b
a.s = b
a.z = h
g.r = i
g.t = b
g.v = c
b.q = d
h.r = g
h.t = b
h.v = d
m.x = k
m.t = b
m.s = b
m.z = g
c.z = b
k.x = m
k.t = b
k.s = b
k.z = g
i.r = g
i.t = b
i.v = c
assert i.r.r.v.z.q.txt == "d"