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

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

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

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

class E:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: A = None
        self.o: B = None
        self.txt = txt

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

h.o = b
b.q = c
b.z = c
b.r = f
j.z = d
c.p = h
f.r = h
f.z = h
f.o = b
d.z = j
assert f.r.o.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.r: A = None
        self.z: A = None
        self.o: B = None
        self.txt = txt

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

h.o = b
b.q = c
b.z = c
b.r = f
j.z = d
c.p = h
f.r = h
f.z = h
f.o = b
d.z = j
assert f.r.o.r.z.txt == "h"