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

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

d = A("d")
n = B("n")
a = A("a")
g = A("g")
i = B("i")
m = B("m")
b = A("b")

d.w = b
n.r = d
n.v = b
a.w = d
g.w = a
i.r = a
i.v = g
m.r = b
m.v = g
b.w = d
assert i.v.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

d = A("d")
n = B("n")
a = A("a")
g = A("g")
i = B("i")
m = B("m")
b = A("b")

d.w = b
n.r = d
n.v = b
a.w = d
g.w = a
i.r = a
i.v = g
m.r = b
m.v = g
b.w = d
assert i.v.w.w.w.w.w.txt == "b"