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

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

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

n = A("n")
j = B("j")
b = C("b")
g = A("g")
i = A("i")
e = C("e")
k = A("k")

n.p = k
n.w = k
j.w = b
j.q = i
b.t = n
g.p = k
g.w = i
i.p = g
i.w = k
e.t = n
k.p = g
k.w = n
assert n.p.p.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.w: A = None
        self.txt = txt

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

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

n = A("n")
j = B("j")
b = C("b")
g = A("g")
i = A("i")
e = C("e")
k = A("k")

n.p = k
n.w = k
j.w = b
j.q = i
b.t = n
g.p = k
g.w = i
i.p = g
i.w = k
e.t = n
k.p = g
k.w = n
assert n.p.p.w.p.txt == "g"