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

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

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

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

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

f = A("f")
a = B("a")
j = C("j")
l = D("l")
c = E("c")
k = A("k")

f.s = k
a.w = k
a.o = l
a.p = f
j.w = c
j.s = c
j.t = a
j.x = a
l.x = f
c.q = a
k.s = f
assert k.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

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

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

f = A("f")
a = B("a")
j = C("j")
l = D("l")
c = E("c")
k = A("k")

f.s = k
a.w = k
a.o = l
a.p = f
j.w = c
j.s = c
j.t = a
j.x = a
l.x = f
c.q = a
k.s = f
assert k.s.s.s.txt == "f"