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

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

class C:
    def __init__(self, txt: str):
        self.u: E = None
        self.txt = txt

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

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

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

h = A("h")
d = B("d")
f = C("f")
c = D("c")
g = E("g")
a = F("a")

h.q = d
d.w = h
d.p = h
d.x = g
f.u = g
c.z = f
c.y = f
c.s = h
g.u = c
g.o = d
g.x = f
a.x = d
a.p = h
assert c.s.q.w.q.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.u: E = None
        self.txt = txt

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

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

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

h = A("h")
d = B("d")
f = C("f")
c = D("c")
g = E("g")
a = F("a")

h.q = d
d.w = h
d.p = h
d.x = g
f.u = g
c.z = f
c.y = f
c.s = h
g.u = c
g.o = d
g.x = f
a.x = d
a.p = h
assert c.s.q.w.q.x.o.txt == "d"