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

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

n = A("n")
b = B("b")
c = A("c")
k = B("k")
d = B("d")
e = B("e")

n.y = c
n.v = d
b.w = e
b.t = d
c.y = n
c.v = k
k.w = d
k.t = d
d.w = b
d.t = k
e.w = b
e.t = d
assert k.w.t.w.w.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.v: B = None
        self.txt = txt

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

n = A("n")
b = B("b")
c = A("c")
k = B("k")
d = B("d")
e = B("e")

n.y = c
n.v = d
b.w = e
b.t = d
c.y = n
c.v = k
k.w = d
k.t = d
d.w = b
d.t = k
e.w = b
e.t = d
assert k.w.t.w.w.t.t.txt == "k"