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

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

d = A("d")
b = B("b")
c = A("c")
h = B("h")
e = B("e")
k = B("k")

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

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

d = A("d")
b = B("b")
c = A("c")
h = B("h")
e = B("e")
k = B("k")

d.r = e
d.p = k
b.s = d
c.r = h
c.p = h
h.s = d
e.s = c
k.s = d
assert c.r.s.p.s.txt == "d"