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

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

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

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

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

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

m.p = j
m.o = j
j.s = m
j.o = m
h.s = m
h.o = m
assert h.s.o.s.txt == "m"