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

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

g = A("g")
n = B("n")
a = B("a")
l = A("l")
b = B("b")
c = B("c")

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

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

g = A("g")
n = B("n")
a = B("a")
l = A("l")
b = B("b")
c = B("c")

g.w = l
g.r = c
n.o = a
a.o = b
l.w = g
l.r = a
b.o = c
c.o = b
assert b.o.o.o.o.o.txt == "c"