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

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

f = A("f")
m = B("m")
e = A("e")
k = B("k")

f.s = k
f.y = e
m.p = k
e.s = m
e.y = f
k.p = m
assert f.y.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: A = None
        self.txt = txt

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

f = A("f")
m = B("m")
e = A("e")
k = B("k")

f.s = k
f.y = e
m.p = k
e.s = m
e.y = f
k.p = m
assert f.y.s.p.txt == "k"