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

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

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

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

m.x = j
j.q = h
j.s = h
j.p = m
h.x = j
h.t = m
assert h.t.x.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

m.x = j
j.q = h
j.s = h
j.p = m
h.x = j
h.t = m
assert h.t.x.s.txt == "h"