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

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

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

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

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

h = A("h")
d = B("d")
e = C("e")
b = D("b")
c = E("c")
i = C("i")
a = A("a")
k = A("k")
l = B("l")

h.r = a
d.q = e
d.w = c
e.z = d
e.p = b
e.x = i
e.r = k
b.s = d
b.x = i
c.p = i
i.z = l
i.p = b
i.x = e
i.r = k
a.r = k
k.r = a
l.q = i
l.w = c
assert i.z.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

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

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

h = A("h")
d = B("d")
e = C("e")
b = D("b")
c = E("c")
i = C("i")
a = A("a")
k = A("k")
l = B("l")

h.r = a
d.q = e
d.w = c
e.z = d
e.p = b
e.x = i
e.r = k
b.s = d
b.x = i
c.p = i
i.z = l
i.p = b
i.x = e
i.r = k
a.r = k
k.r = a
l.q = i
l.w = c
assert i.z.w.p.txt == "i"