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

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

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

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

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

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

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

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

d.w = j
g.y = d
j.x = g
j.p = k
j.o = d
k.w = j
assert k.w.p.w.o.txt == "d"