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

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

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

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

k.o = f
k.r = f
k.p = m
m.y = j
m.r = f
m.o = k
f.v = m
f.z = m
j.y = m
j.r = f
j.o = k
assert k.p.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.r: C = None
        self.p: B = None
        self.txt = txt

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

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

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

k.o = f
k.r = f
k.p = m
m.y = j
m.r = f
m.o = k
f.v = m
f.z = m
j.y = m
j.r = f
j.o = k
assert k.p.r.v.txt == "m"