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

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

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

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

h.y = i
c.x = i
c.u = m
m.p = h
i.p = h
assert h.y.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

h.y = i
c.x = i
c.u = m
m.p = h
i.p = h
assert h.y.p.y.txt == "i"