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

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

h = A("h")
d = B("d")
b = B("b")
m = B("m")
n = A("n")
l = B("l")

h.y = n
h.w = m
d.v = n
b.v = n
m.v = h
n.y = h
n.w = l
l.v = n
assert d.v.w.v.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.w: B = None
        self.txt = txt

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

h = A("h")
d = B("d")
b = B("b")
m = B("m")
n = A("n")
l = B("l")

h.y = n
h.w = m
d.v = n
b.v = n
m.v = h
n.y = h
n.w = l
l.v = n
assert d.v.w.v.w.txt == "l"