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

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

b = A("b")
g = B("g")
m = B("m")
j = A("j")

b.u = g
b.w = j
g.o = m
m.o = g
j.u = g
j.w = b
assert j.u.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.w: A = None
        self.txt = txt

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

b = A("b")
g = B("g")
m = B("m")
j = A("j")

b.u = g
b.w = j
g.o = m
m.o = g
j.u = g
j.w = b
assert j.u.o.o.o.txt == "m"