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

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

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

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

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

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

g.w = k
b.o = j
b.r = k
j.w = b
k.o = j
k.r = b
assert b.r.o.w.r.txt == "k"