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

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

f = A("f")
e = B("e")
d = B("d")
b = A("b")
k = B("k")

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

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

f = A("f")
e = B("e")
d = B("d")
b = A("b")
k = B("k")

f.p = d
f.y = e
e.s = f
e.r = k
d.s = f
d.r = k
b.p = d
b.y = k
k.s = b
k.r = e
assert f.p.s.p.txt == "d"