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

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

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

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

b = A("b")
f = B("f")
e = C("e")
j = D("j")
n = A("n")
d = C("d")
c = D("c")
a = A("a")

b.q = n
b.w = f
f.y = e
e.x = a
e.o = j
j.q = c
j.z = d
n.q = b
n.w = f
d.x = a
d.o = c
c.q = j
c.z = e
a.q = b
a.w = f
assert d.x.q.q.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.w: B = None
        self.txt = txt

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

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

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

b = A("b")
f = B("f")
e = C("e")
j = D("j")
n = A("n")
d = C("d")
c = D("c")
a = A("a")

b.q = n
b.w = f
f.y = e
e.x = a
e.o = j
j.q = c
j.z = d
n.q = b
n.w = f
d.x = a
d.o = c
c.q = j
c.z = e
a.q = b
a.w = f
assert d.x.q.q.q.w.txt == "f"