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

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

d = A("d")
l = B("l")
h = A("h")
i = B("i")
n = B("n")
f = B("f")

d.v = n
d.u = h
l.w = i
h.v = l
h.u = d
i.w = f
n.w = l
f.w = n
assert h.v.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.u: A = None
        self.txt = txt

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

d = A("d")
l = B("l")
h = A("h")
i = B("i")
n = B("n")
f = B("f")

d.v = n
d.u = h
l.w = i
h.v = l
h.u = d
i.w = f
n.w = l
f.w = n
assert h.v.w.w.w.txt == "n"