class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.p: B = 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.q: B = None
        self.s: A = None
        self.t: C = None
        self.txt = txt

h = A("h")
d = B("d")
m = C("m")
c = C("c")

h.x = c
h.p = d
d.o = c
m.q = d
m.s = h
m.t = c
c.q = d
c.s = h
c.t = m
assert d.o.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.p: B = 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.q: B = None
        self.s: A = None
        self.t: C = None
        self.txt = txt

h = A("h")
d = B("d")
m = C("m")
c = C("c")

h.x = c
h.p = d
d.o = c
m.q = d
m.s = h
m.t = c
c.q = d
c.s = h
c.t = m
assert d.o.t.t.txt == "c"