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

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

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

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

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

d.y = a
a.w = g
g.w = h
c.x = m
e.w = d
n.x = m
h.y = a
m.x = n
assert g.w.y.w.w.y.w.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

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

d.y = a
a.w = g
g.w = h
c.x = m
e.w = d
n.x = m
h.y = a
m.x = n
assert g.w.y.w.w.y.w.w.y.txt == "a"