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

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

g = A("g")
l = B("l")
d = A("d")
k = B("k")
j = B("j")
f = B("f")

g.w = d
g.u = d
l.o = d
d.w = g
d.u = g
k.o = g
j.o = g
f.o = d
assert k.o.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.u: A = None
        self.txt = txt

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

g = A("g")
l = B("l")
d = A("d")
k = B("k")
j = B("j")
f = B("f")

g.w = d
g.u = d
l.o = d
d.w = g
d.u = g
k.o = g
j.o = g
f.o = d
assert k.o.w.u.txt == "g"