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

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

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

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

f.z = e
f.x = e
j.y = f
e.p = j
e.y = j
e.q = j
assert f.z.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.x: C = None
        self.txt = txt

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

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

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

f.z = e
f.x = e
j.y = f
e.p = j
e.y = j
e.q = j
assert f.z.q.y.txt == "f"