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

class B:
    def __init__(self, txt: str):
        self.t: D = None
        self.x: D = None
        self.r: F = None
        self.txt = txt

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

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

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

class F:
    def __init__(self, txt: str):
        self.p: A = None
        self.t: E = None
        self.q: A = None
        self.y: B = None
        self.v: A = None
        self.s: A = None
        self.txt = txt

h = A("h")
a = B("a")
k = C("k")
d = D("d")
i = E("i")
m = F("m")

h.z = a
a.t = d
a.x = d
a.r = m
k.o = h
d.t = m
d.z = h
d.q = a
d.w = k
i.q = d
m.p = h
m.q = h
m.v = h
m.s = h
m.t = i
m.y = a
assert a.r.t.q.z.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: D = None
        self.x: D = None
        self.r: F = None
        self.txt = txt

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

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

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

class F:
    def __init__(self, txt: str):
        self.p: A = None
        self.t: E = None
        self.q: A = None
        self.y: B = None
        self.v: A = None
        self.s: A = None
        self.txt = txt

h = A("h")
a = B("a")
k = C("k")
d = D("d")
i = E("i")
m = F("m")

h.z = a
a.t = d
a.x = d
a.r = m
k.o = h
d.t = m
d.z = h
d.q = a
d.w = k
i.q = d
m.p = h
m.q = h
m.v = h
m.s = h
m.t = i
m.y = a
assert a.r.t.q.z.z.r.txt == "m"