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

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

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

n = A("n")
c = B("c")
a = C("a")
d = A("d")
l = C("l")
h = B("h")

n.w = d
c.q = h
c.w = h
a.s = l
a.v = n
d.w = n
l.s = a
l.v = n
h.q = c
h.w = c
assert a.v.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

n = A("n")
c = B("c")
a = C("a")
d = A("d")
l = C("l")
h = B("h")

n.w = d
c.q = h
c.w = h
a.s = l
a.v = n
d.w = n
l.s = a
l.v = n
h.q = c
h.w = c
assert a.v.w.w.w.w.txt == "n"