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

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

l = A("l")
h = B("h")
f = A("f")

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

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

l = A("l")
h = B("h")
f = A("f")

l.y = h
l.p = f
h.s = f
f.y = h
f.p = l
assert l.p.y.s.txt == "f"