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

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

b = A("b")
j = B("j")
c = B("c")
d = A("d")
a = A("a")
k = B("k")
f = A("f")

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

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

b = A("b")
j = B("j")
c = B("c")
d = A("d")
a = A("a")
k = B("k")
f = A("f")

b.w = k
b.y = f
j.x = a
j.o = b
c.x = b
c.o = d
d.w = j
d.y = a
a.w = j
a.y = d
k.x = f
k.o = a
f.w = k
f.y = d
assert k.x.y.y.w.o.txt == "b"