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

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

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

n = A("n")
j = B("j")
g = C("g")
i = C("i")

n.w = g
n.x = g
j.w = n
g.p = n
g.t = i
i.p = n
i.t = g
assert i.t.t.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.x: C = None
        self.txt = txt

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

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

n = A("n")
j = B("j")
g = C("g")
i = C("i")

n.w = g
n.x = g
j.w = n
g.p = n
g.t = i
i.p = n
i.t = g
assert i.t.t.p.w.txt == "g"