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

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

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

h = A("h")
e = B("e")
j = C("j")

h.q = e
e.z = h
e.q = j
j.y = e
assert j.y.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

h = A("h")
e = B("e")
j = C("j")

h.q = e
e.z = h
e.q = j
j.y = e
assert j.y.z.q.txt == "e"