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

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

class C:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

i = A("i")
j = B("j")
d = C("d")
e = D("e")
a = C("a")
h = C("h")
c = A("c")
m = D("m")
f = A("f")
g = D("g")

i.p = j
i.s = j
j.o = m
j.w = e
d.z = e
e.x = g
e.q = m
e.o = f
a.z = g
h.z = g
c.p = j
c.s = j
m.x = g
m.q = e
m.o = c
f.p = j
f.s = j
g.x = m
g.q = m
g.o = c
assert f.p.w.q.x.q.x.o.p.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.z: D = None
        self.txt = txt

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

i = A("i")
j = B("j")
d = C("d")
e = D("e")
a = C("a")
h = C("h")
c = A("c")
m = D("m")
f = A("f")
g = D("g")

i.p = j
i.s = j
j.o = m
j.w = e
d.z = e
e.x = g
e.q = m
e.o = f
a.z = g
h.z = g
c.p = j
c.s = j
m.x = g
m.q = e
m.o = c
f.p = j
f.s = j
g.x = m
g.q = m
g.o = c
assert f.p.w.q.x.q.x.o.p.o.x.txt == "g"