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

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

l = A("l")
m = B("m")
h = A("h")
c = B("c")

l.r = h
l.v = c
m.r = l
h.r = l
h.v = c
c.r = l
assert m.r.v.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.v: B = None
        self.txt = txt

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

l = A("l")
m = B("m")
h = A("h")
c = B("c")

l.r = h
l.v = c
m.r = l
h.r = l
h.v = c
c.r = l
assert m.r.v.r.r.txt == "h"