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

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

d = A("d")
l = B("l")
i = A("i")
b = A("b")
k = B("k")
h = A("h")
m = B("m")

d.v = b
l.p = b
l.w = i
i.v = d
b.v = h
k.p = b
k.w = i
h.v = b
m.p = h
m.w = i
assert d.v.v.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

d = A("d")
l = B("l")
i = A("i")
b = A("b")
k = B("k")
h = A("h")
m = B("m")

d.v = b
l.p = b
l.w = i
i.v = d
b.v = h
k.p = b
k.w = i
h.v = b
m.p = h
m.w = i
assert d.v.v.v.v.v.v.v.txt == "b"