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

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

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

b = A("b")
h = B("h")
e = C("e")
g = A("g")

b.x = h
b.r = g
b.o = e
h.x = g
e.p = b
e.y = g
g.x = h
g.r = b
g.o = e
assert h.x.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.r: A = None
        self.o: C = None
        self.txt = txt

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

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

b = A("b")
h = B("h")
e = C("e")
g = A("g")

b.x = h
b.r = g
b.o = e
h.x = g
e.p = b
e.y = g
g.x = h
g.r = b
g.o = e
assert h.x.o.p.txt == "b"