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

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

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

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

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

n.w = g
n.t = h
c.w = d
c.s = d
h.z = d
h.r = d
d.v = a
a.z = d
a.r = d
g.w = n
g.t = i
i.z = d
i.r = d
assert g.w.w.w.w.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.t: C = None
        self.txt = txt

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

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

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

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

n.w = g
n.t = h
c.w = d
c.s = d
h.z = d
h.r = d
d.v = a
a.z = d
a.r = d
g.w = n
g.t = i
i.z = d
i.r = d
assert g.w.w.w.w.w.t.txt == "h"