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

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.v: H = None
        self.txt = txt

class G:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

class H:
    def __init__(self, txt: str):
        self.w: F = None
        self.y: B = None
        self.txt = txt

a = A("a")
g = B("g")
d = C("d")
e = D("e")
f = E("f")
k = F("k")
j = G("j")
c = H("c")
m = F("m")
i = B("i")

a.p = i
g.x = d
d.z = c
d.q = e
e.w = a
e.r = f
e.x = d
f.w = a
f.y = a
f.t = k
f.z = d
k.v = c
j.u = e
c.w = k
c.y = i
m.v = c
i.x = d
assert a.p.x.z.y.x.q.w.p.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

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

class F:
    def __init__(self, txt: str):
        self.v: H = None
        self.txt = txt

class G:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

class H:
    def __init__(self, txt: str):
        self.w: F = None
        self.y: B = None
        self.txt = txt

a = A("a")
g = B("g")
d = C("d")
e = D("e")
f = E("f")
k = F("k")
j = G("j")
c = H("c")
m = F("m")
i = B("i")

a.p = i
g.x = d
d.z = c
d.q = e
e.w = a
e.r = f
e.x = d
f.w = a
f.y = a
f.t = k
f.z = d
k.v = c
j.u = e
c.w = k
c.y = i
m.v = c
i.x = d
assert a.p.x.z.y.x.q.w.p.x.q.txt == "e"