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

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

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

c = A("c")
g = B("g")
h = C("h")
f = C("f")

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

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

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

c = A("c")
g = B("g")
h = C("h")
f = C("f")

c.x = h
g.o = f
g.s = c
g.y = c
h.r = g
h.o = g
h.p = f
f.r = g
f.o = g
f.p = h
assert f.p.p.r.o.txt == "f"