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

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

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

g = A("g")
m = B("m")
k = C("k")
e = B("e")

g.w = e
m.p = g
m.y = g
k.r = g
e.p = g
e.y = g
assert m.p.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
k = C("k")
e = B("e")

g.w = e
m.p = g
m.y = g
k.r = g
e.p = g
e.y = g
assert m.p.w.p.txt == "g"