class A:
    def __init__(self, txt: str):
        self.o: B = 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

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

j.o = d
d.x = j
m.p = j
m.y = k
k.o = d
assert j.o.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = 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

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

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