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

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

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

d = A("d")
g = B("g")
m = C("m")
j = A("j")
e = B("e")
n = B("n")
a = A("a")
f = B("f")
k = C("k")

d.t = m
d.w = j
g.x = d
g.w = k
m.p = e
j.t = m
j.w = d
e.x = d
e.w = k
n.x = a
n.w = k
a.t = k
a.w = d
f.x = d
f.w = k
k.p = e
assert g.w.p.w.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.w: A = None
        self.txt = txt

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

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

d = A("d")
g = B("g")
m = C("m")
j = A("j")
e = B("e")
n = B("n")
a = A("a")
f = B("f")
k = C("k")

d.t = m
d.w = j
g.x = d
g.w = k
m.p = e
j.t = m
j.w = d
e.x = d
e.w = k
n.x = a
n.w = k
a.t = k
a.w = d
f.x = d
f.w = k
k.p = e
assert g.w.p.w.p.x.txt == "d"