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

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

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

d = A("d")
b = B("b")
a = C("a")
g = B("g")
f = B("f")
m = B("m")
h = C("h")
e = C("e")

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

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

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

d = A("d")
b = B("b")
a = C("a")
g = B("g")
f = B("f")
m = B("m")
h = C("h")
e = C("e")

d.w = f
b.q = f
a.w = d
g.q = f
f.q = g
m.q = g
h.w = d
e.w = d
assert h.w.w.q.q.q.q.q.q.txt == "f"