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

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

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

n = A("n")
j = B("j")
i = C("i")
k = B("k")

n.x = i
n.y = i
j.r = n
j.y = n
j.o = i
i.p = n
i.o = k
i.v = j
k.r = n
k.y = n
k.o = i
assert j.r.x.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.y: C = None
        self.txt = txt

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

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

n = A("n")
j = B("j")
i = C("i")
k = B("k")

n.x = i
n.y = i
j.r = n
j.y = n
j.o = i
i.p = n
i.o = k
i.v = j
k.r = n
k.y = n
k.o = i
assert j.r.x.p.y.txt == "i"