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

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

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

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

f = A("f")
c = B("c")
n = C("n")
m = D("m")
h = D("h")
g = C("g")
i = A("i")

f.t = i
f.v = g
f.y = g
c.o = f
n.z = m
m.w = f
h.w = f
g.z = m
i.t = f
i.v = n
i.y = n
assert n.z.w.v.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.v: C = None
        self.y: C = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
n = C("n")
m = D("m")
h = D("h")
g = C("g")
i = A("i")

f.t = i
f.v = g
f.y = g
c.o = f
n.z = m
m.w = f
h.w = f
g.z = m
i.t = f
i.v = n
i.y = n
assert n.z.w.v.z.txt == "m"