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

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

g = A("g")
n = B("n")
k = B("k")
a = B("a")
b = B("b")

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

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

g = A("g")
n = B("n")
k = B("k")
a = B("a")
b = B("b")

g.r = n
n.w = g
k.w = g
a.w = g
b.w = g
assert a.w.r.w.r.w.txt == "g"