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

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

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

h.r = m
m.q = h
m.u = k
k.r = m
assert k.r.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

h.r = m
m.q = h
m.u = k
k.r = m
assert k.r.u.r.txt == "m"