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

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

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

b.w = d
g.u = d
g.w = d
d.w = b
i.w = m
m.w = b
n.u = b
n.w = m
assert n.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.u: A = None
        self.w: A = None
        self.txt = txt

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

b.w = d
g.u = d
g.w = d
d.w = b
i.w = m
m.w = b
n.u = b
n.w = m
assert n.w.w.w.txt == "d"