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

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

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

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

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

b = A("b")
h = B("h")
j = C("j")
f = D("f")
c = E("c")
a = A("a")
g = E("g")

b.z = a
b.w = f
h.q = f
j.r = h
j.x = h
f.y = j
c.z = h
c.s = f
c.o = j
a.z = b
a.w = f
g.z = h
g.s = f
g.o = j
assert j.r.q.y.r.q.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.w: D = None
        self.txt = txt

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

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

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

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

b = A("b")
h = B("h")
j = C("j")
f = D("f")
c = E("c")
a = A("a")
g = E("g")

b.z = a
b.w = f
h.q = f
j.r = h
j.x = h
f.y = j
c.z = h
c.s = f
c.o = j
a.z = b
a.w = f
g.z = h
g.s = f
g.o = j
assert j.r.q.y.r.q.y.r.txt == "h"