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

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

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

b = A("b")
h = B("h")
l = C("l")
j = A("j")
f = C("f")
d = B("d")
k = B("k")

b.w = k
h.v = k
l.p = f
l.q = f
j.w = k
f.p = l
f.q = l
d.v = h
k.v = d
assert k.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

b = A("b")
h = B("h")
l = C("l")
j = A("j")
f = C("f")
d = B("d")
k = B("k")

b.w = k
h.v = k
l.p = f
l.q = f
j.w = k
f.p = l
f.q = l
d.v = h
k.v = d
assert k.v.v.v.v.txt == "d"