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

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

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

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

m.x = g
g.y = m
g.p = h
h.v = g
h.x = m
assert g.y.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

m.x = g
g.y = m
g.p = h
h.v = g
h.x = m
assert g.y.x.p.txt == "h"