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

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

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

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

f = A("f")
h = B("h")
d = C("d")
b = D("b")
e = A("e")
n = C("n")
a = B("a")
m = B("m")

f.z = b
f.w = b
f.s = n
f.q = n
h.u = m
h.r = m
h.p = m
h.z = f
d.r = n
d.t = a
b.r = e
b.q = m
e.z = b
e.w = b
e.s = d
e.q = d
n.r = d
n.t = h
a.u = h
a.p = h
a.z = f
a.r = m
m.u = h
m.r = h
m.p = h
m.z = f
assert n.r.r.t.z.q.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.s: C = None
        self.q: C = None
        self.w: D = None
        self.txt = txt

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

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

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

f = A("f")
h = B("h")
d = C("d")
b = D("b")
e = A("e")
n = C("n")
a = B("a")
m = B("m")

f.z = b
f.w = b
f.s = n
f.q = n
h.u = m
h.r = m
h.p = m
h.z = f
d.r = n
d.t = a
b.r = e
b.q = m
e.z = b
e.w = b
e.s = d
e.q = d
n.r = d
n.t = h
a.u = h
a.p = h
a.z = f
a.r = m
m.u = h
m.r = h
m.p = h
m.z = f
assert n.r.r.t.z.q.t.z.txt == "f"