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

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

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

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

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

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

k.s = h
h.p = k
h.r = i
i.s = h
assert i.s.r.s.txt == "h"