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

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

i = A("i")
a = B("a")
f = A("f")
b = B("b")
k = A("k")
j = B("j")

i.w = b
i.y = a
a.y = k
a.x = b
f.w = a
f.y = b
b.y = f
b.x = j
k.w = b
k.y = b
j.y = f
j.x = a
assert k.w.y.y.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.y: B = None
        self.txt = txt

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

i = A("i")
a = B("a")
f = A("f")
b = B("b")
k = A("k")
j = B("j")

i.w = b
i.y = a
a.y = k
a.x = b
f.w = a
f.y = b
b.y = f
b.x = j
k.w = b
k.y = b
j.y = f
j.x = a
assert k.w.y.y.x.x.x.txt == "b"