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

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

m = A("m")
i = B("i")
h = B("h")

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

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

m = A("m")
i = B("i")
h = B("h")

m.p = i
i.s = m
h.s = m
assert i.s.p.s.txt == "m"