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: B = None
        self.txt = txt

m = A("m")
c = B("c")
a = B("a")
f = B("f")

m.s = c
c.v = m
c.p = a
a.v = m
a.p = c
f.v = m
f.p = c
assert f.v.s.p.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: B = None
        self.txt = txt

m = A("m")
c = B("c")
a = B("a")
f = B("f")

m.s = c
c.v = m
c.p = a
a.v = m
a.p = c
f.v = m
f.p = c
assert f.v.s.p.txt == "a"