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

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

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

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

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

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

e.s = f
e.w = f
l.p = e
l.r = e
f.p = e
f.r = e
k.p = e
k.r = e
assert f.p.s.p.txt == "e"