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

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

i = A("i")
a = B("a")
d = A("d")
n = B("n")
g = B("g")

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

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

i = A("i")
a = B("a")
d = A("d")
n = B("n")
g = B("g")

i.r = d
i.y = d
a.o = n
a.w = n
d.r = i
d.y = i
n.o = a
n.w = g
g.o = n
g.w = a
assert a.o.w.w.o.txt == "n"