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

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

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

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

c.v = d
c.q = e
m.w = d
h.w = d
e.w = d
d.w = m
f.w = m
assert d.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.q: C = None
        self.txt = txt

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

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

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

c.v = d
c.q = e
m.w = d
h.w = d
e.w = d
d.w = m
f.w = m
assert d.w.w.w.w.w.txt == "m"