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

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

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

d = A("d")
g = B("g")
a = C("a")
k = C("k")

d.r = a
d.x = a
d.o = g
g.p = d
g.y = d
a.u = k
a.r = d
k.u = a
k.r = d
assert g.p.o.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.o: B = None
        self.x: C = None
        self.txt = txt

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

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

d = A("d")
g = B("g")
a = C("a")
k = C("k")

d.r = a
d.x = a
d.o = g
g.p = d
g.y = d
a.u = k
a.r = d
k.u = a
k.r = d
assert g.p.o.y.o.txt == "g"