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

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

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

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

f = A("f")
a = B("a")
m = C("m")
c = D("c")
e = D("e")

f.y = e
f.v = m
f.o = a
a.q = f
a.o = m
m.s = a
m.q = f
c.x = f
c.q = a
e.x = f
e.q = a
assert a.o.s.q.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.v: C = None
        self.o: B = None
        self.txt = txt

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

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

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

f = A("f")
a = B("a")
m = C("m")
c = D("c")
e = D("e")

f.y = e
f.v = m
f.o = a
a.q = f
a.o = m
m.s = a
m.q = f
c.x = f
c.q = a
e.x = f
e.q = a
assert a.o.s.q.y.x.txt == "f"