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

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

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

d.x = m
h.r = d
h.t = m
m.x = d
assert d.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

d.x = m
h.r = d
h.t = m
m.x = d
assert d.x.x.x.txt == "m"