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

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

d = A("d")
e = B("e")
n = B("n")

d.u = n
d.r = n
e.p = d
n.p = d
assert e.p.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.r: B = None
        self.txt = txt

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

d = A("d")
e = B("e")
n = B("n")

d.u = n
d.r = n
e.p = d
n.p = d
assert e.p.u.p.txt == "d"