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

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

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

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

a = A("a")
e = B("e")
n = C("n")
f = D("f")
k = D("k")
h = B("h")

a.q = k
e.x = f
e.t = f
e.o = n
e.u = h
n.r = e
f.r = a
f.p = e
k.r = a
k.p = h
h.x = k
h.o = n
h.t = f
h.u = e
assert a.q.r.q.p.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

a = A("a")
e = B("e")
n = C("n")
f = D("f")
k = D("k")
h = B("h")

a.q = k
e.x = f
e.t = f
e.o = n
e.u = h
n.r = e
f.r = a
f.p = e
k.r = a
k.p = h
h.x = k
h.o = n
h.t = f
h.u = e
assert a.q.r.q.p.t.p.txt == "e"