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

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.w: C = None
        self.s: D = None
        self.v: D = None
        self.txt = txt

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

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

f = A("f")
j = B("j")
m = C("m")
e = D("e")
l = D("l")

f.o = m
j.y = f
j.w = m
j.s = e
j.v = e
m.w = e
m.v = e
e.z = j
e.s = l
e.q = l
e.x = f
l.z = j
l.s = e
l.q = e
l.x = f
assert l.z.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.w: C = None
        self.s: D = None
        self.v: D = None
        self.txt = txt

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

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

f = A("f")
j = B("j")
m = C("m")
e = D("e")
l = D("l")

f.o = m
j.y = f
j.w = m
j.s = e
j.v = e
m.w = e
m.v = e
e.z = j
e.s = l
e.q = l
e.x = f
l.z = j
l.s = e
l.q = e
l.x = f
assert l.z.s.x.txt == "f"