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

class B:
    def __init__(self, txt: str):
        self.r: D = None
        self.z: F = None
        self.t: A = None
        self.u: D = None
        self.y: F = None
        self.p: A = None
        self.txt = txt

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

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

class E:
    def __init__(self, txt: str):
        self.t: A = None
        self.x: A = None
        self.r: F = None
        self.q: C = None
        self.p: C = None
        self.txt = txt

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

d = A("d")
g = B("g")
a = C("a")
f = D("f")
l = E("l")
i = F("i")

d.r = a
g.r = f
g.u = f
g.z = i
g.y = i
g.t = d
g.p = d
a.w = g
f.t = a
l.t = d
l.x = d
l.r = i
l.q = a
l.p = a
i.q = f
i.z = a
assert i.q.t.w.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: D = None
        self.z: F = None
        self.t: A = None
        self.u: D = None
        self.y: F = None
        self.p: A = None
        self.txt = txt

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

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

class E:
    def __init__(self, txt: str):
        self.t: A = None
        self.x: A = None
        self.r: F = None
        self.q: C = None
        self.p: C = None
        self.txt = txt

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

d = A("d")
g = B("g")
a = C("a")
f = D("f")
l = E("l")
i = F("i")

d.r = a
g.r = f
g.u = f
g.z = i
g.y = i
g.t = d
g.p = d
a.w = g
f.t = a
l.t = d
l.x = d
l.r = i
l.q = a
l.p = a
i.q = f
i.z = a
assert i.q.t.w.z.z.txt == "a"