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

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

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

h = A("h")
d = B("d")
k = C("k")
c = A("c")
i = C("i")
f = A("f")
m = C("m")
e = B("e")
n = B("n")

h.w = d
d.q = m
d.r = f
d.y = n
k.r = h
c.w = n
i.r = f
f.w = d
m.r = h
e.q = m
e.r = f
e.y = d
n.q = m
n.r = c
n.y = d
assert n.r.w.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

h = A("h")
d = B("d")
k = C("k")
c = A("c")
i = C("i")
f = A("f")
m = C("m")
e = B("e")
n = B("n")

h.w = d
d.q = m
d.r = f
d.y = n
k.r = h
c.w = n
i.r = f
f.w = d
m.r = h
e.q = m
e.r = f
e.y = d
n.q = m
n.r = c
n.y = d
assert n.r.w.y.y.txt == "n"