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

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

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

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

class E:
    def __init__(self, txt: str):
        self.u: A = None
        self.o: B = None
        self.w: A = None
        self.y: A = None
        self.s: B = None
        self.txt = txt

f = A("f")
h = B("h")
j = C("j")
e = D("e")
k = E("k")

f.p = h
f.x = e
h.w = f
j.y = h
e.y = h
e.r = h
k.u = f
k.w = f
k.y = f
k.o = h
k.s = h
assert e.r.w.x.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.x: D = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.u: A = None
        self.o: B = None
        self.w: A = None
        self.y: A = None
        self.s: B = None
        self.txt = txt

f = A("f")
h = B("h")
j = C("j")
e = D("e")
k = E("k")

f.p = h
f.x = e
h.w = f
j.y = h
e.y = h
e.r = h
k.u = f
k.w = f
k.y = f
k.o = h
k.s = h
assert e.r.w.x.r.w.txt == "f"