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

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

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

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

k.p = f
m.w = g
m.o = f
f.v = m
g.v = m
assert f.v.o.v.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

k.p = f
m.w = g
m.o = f
f.v = m
g.v = m
assert f.v.o.v.o.txt == "f"