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

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

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

a = A("a")
l = B("l")
h = C("h")
i = B("i")
c = A("c")
b = B("b")
m = A("m")
d = C("d")

a.q = h
l.y = c
l.r = m
h.y = c
h.v = c
h.s = b
i.y = m
i.r = a
c.q = d
b.y = m
b.r = c
m.q = h
d.y = a
d.s = l
d.v = c
assert m.q.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

a = A("a")
l = B("l")
h = C("h")
i = B("i")
c = A("c")
b = B("b")
m = A("m")
d = C("d")

a.q = h
l.y = c
l.r = m
h.y = c
h.v = c
h.s = b
i.y = m
i.r = a
c.q = d
b.y = m
b.r = c
m.q = h
d.y = a
d.s = l
d.v = c
assert m.q.s.r.txt == "c"