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

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

n = A("n")
d = B("d")
f = B("f")
i = B("i")

n.o = d
n.w = i
d.y = n
f.y = n
i.y = n
assert n.w.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.w: B = None
        self.txt = txt

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

n = A("n")
d = B("d")
f = B("f")
i = B("i")

n.o = d
n.w = i
d.y = n
f.y = n
i.y = n
assert n.w.y.o.txt == "d"