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

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

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

c = A("c")
d = B("d")
f = C("f")
k = B("k")
m = A("m")
e = C("e")
b = B("b")
g = A("g")
a = C("a")

c.x = g
d.t = k
d.s = e
d.w = a
f.q = e
f.y = b
f.p = c
k.t = d
k.s = a
k.w = a
m.x = g
e.q = a
e.y = k
e.p = g
b.t = k
b.s = a
b.w = f
g.x = m
a.q = e
a.y = d
a.p = c
assert a.p.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

c = A("c")
d = B("d")
f = C("f")
k = B("k")
m = A("m")
e = C("e")
b = B("b")
g = A("g")
a = C("a")

c.x = g
d.t = k
d.s = e
d.w = a
f.q = e
f.y = b
f.p = c
k.t = d
k.s = a
k.w = a
m.x = g
e.q = a
e.y = k
e.p = g
b.t = k
b.s = a
b.w = f
g.x = m
a.q = e
a.y = d
a.p = c
assert a.p.x.x.x.txt == "g"