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

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

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

h = A("h")
k = B("k")
c = C("c")

h.w = c
k.o = c
c.o = k
c.q = h
assert k.o.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

h = A("h")
k = B("k")
c = C("c")

h.w = c
k.o = c
c.o = k
c.q = h
assert k.o.q.w.txt == "c"