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

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

c = A("c")
n = B("n")
m = A("m")
d = B("d")
a = A("a")
f = B("f")

c.w = a
n.v = f
m.w = c
d.v = n
a.w = c
f.v = d
assert d.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

c = A("c")
n = B("n")
m = A("m")
d = B("d")
a = A("a")
f = B("f")

c.w = a
n.v = f
m.w = c
d.v = n
a.w = c
f.v = d
assert d.v.v.v.txt == "d"