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

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

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

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

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

g.z = h
h.u = i
h.y = b
h.z = g
h.p = m
m.p = a
m.t = a
m.v = g
m.o = k
i.u = m
k.z = a
n.u = m
a.u = n
a.y = b
a.z = b
a.p = m
b.z = h
assert b.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

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

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

g.z = h
h.u = i
h.y = b
h.z = g
h.p = m
m.p = a
m.t = a
m.v = g
m.o = k
i.u = m
k.z = a
n.u = m
a.u = n
a.y = b
a.z = b
a.p = m
b.z = h
assert b.z.y.z.txt == "h"