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

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

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

b = A("b")
h = B("h")
a = C("a")
f = C("f")

b.y = f
h.q = a
h.y = a
h.x = f
a.v = h
a.s = h
a.q = h
f.v = h
f.s = h
f.q = h
assert b.y.v.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

b = A("b")
h = B("h")
a = C("a")
f = C("f")

b.y = f
h.q = a
h.y = a
h.x = f
a.v = h
a.s = h
a.q = h
f.v = h
f.s = h
f.q = h
assert b.y.v.y.v.txt == "h"