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

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

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

b = A("b")
m = B("m")
n = C("n")
f = C("f")
h = B("h")
k = A("k")

b.s = h
m.v = k
m.p = k
n.x = h
f.x = h
h.v = b
h.p = k
k.s = m
assert n.x.v.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

b = A("b")
m = B("m")
n = C("n")
f = C("f")
h = B("h")
k = A("k")

b.s = h
m.v = k
m.p = k
n.x = h
f.x = h
h.v = b
h.p = k
k.s = m
assert n.x.v.s.v.txt == "b"