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

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

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

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

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

f.o = a
f.w = h
f.q = e
e.w = a
h.q = j
h.v = e
a.r = j
j.o = a
j.w = h
j.q = e
m.w = a
assert a.r.o.r.q.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.w: C = None
        self.q: B = None
        self.txt = txt

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

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

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

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

f.o = a
f.w = h
f.q = e
e.w = a
h.q = j
h.v = e
a.r = j
j.o = a
j.w = h
j.q = e
m.w = a
assert a.r.o.r.q.w.r.txt == "j"