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

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.z: G = None
        self.y: E = None
        self.p: D = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.o: F = None
        self.p: G = None
        self.s: B = None
        self.u: A = None
        self.w: G = None
        self.txt = txt

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

class F:
    def __init__(self, txt: str):
        self.r: G = None
        self.t: E = None
        self.txt = txt

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

d = A("d")
f = B("f")
c = C("c")
m = D("m")
h = E("h")
n = F("n")
g = G("g")

d.x = h
f.w = m
f.p = m
f.z = g
f.y = h
c.r = h
c.z = d
m.o = n
m.p = g
m.w = g
m.s = f
m.u = d
h.y = c
n.r = g
n.t = h
g.x = d
g.z = d
assert d.x.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.x: E = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.z: G = None
        self.y: E = None
        self.p: D = None
        self.txt = txt

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

class D:
    def __init__(self, txt: str):
        self.o: F = None
        self.p: G = None
        self.s: B = None
        self.u: A = None
        self.w: G = None
        self.txt = txt

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

class F:
    def __init__(self, txt: str):
        self.r: G = None
        self.t: E = None
        self.txt = txt

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

d = A("d")
f = B("f")
c = C("c")
m = D("m")
h = E("h")
n = F("n")
g = G("g")

d.x = h
f.w = m
f.p = m
f.z = g
f.y = h
c.r = h
c.z = d
m.o = n
m.p = g
m.w = g
m.s = f
m.u = d
h.y = c
n.r = g
n.t = h
g.x = d
g.z = d
assert d.x.y.z.txt == "d"