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

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

c = A("c")
i = B("i")
j = B("j")
g = A("g")
b = B("b")

c.o = g
i.w = j
i.p = b
j.w = i
j.p = b
g.o = c
b.w = j
b.p = i
assert g.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

c = A("c")
i = B("i")
j = B("j")
g = A("g")
b = B("b")

c.o = g
i.w = j
i.p = b
j.w = i
j.p = b
g.o = c
b.w = j
b.p = i
assert g.o.o.o.o.o.txt == "c"