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

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

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

g = A("g")
h = B("h")
c = C("c")
e = A("e")

g.x = e
g.q = c
h.z = c
c.z = g
e.x = g
e.q = c
assert h.z.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: C = None
        self.txt = txt

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

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

g = A("g")
h = B("h")
c = C("c")
e = A("e")

g.x = e
g.q = c
h.z = c
c.z = g
e.x = g
e.q = c
assert h.z.z.q.z.txt == "g"