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

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

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

i = A("i")
k = B("k")
g = C("g")
b = A("b")

i.w = b
i.p = g
k.r = g
g.s = i
b.w = i
b.p = g
assert i.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.p: C = None
        self.txt = txt

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

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

i = A("i")
k = B("k")
g = C("g")
b = A("b")

i.w = b
i.p = g
k.r = g
g.s = i
b.w = i
b.p = g
assert i.w.w.w.w.txt == "i"