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

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

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

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

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

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

b = A("b")
g = B("g")
a = C("a")
m = D("m")
f = E("f")
e = F("e")

b.p = g
b.q = a
g.r = m
g.x = e
a.w = g
a.r = e
m.v = b
m.p = e
f.q = e
f.y = e
e.z = b
assert a.r.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: C = None
        self.txt = txt

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

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

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

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

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

b = A("b")
g = B("g")
a = C("a")
m = D("m")
f = E("f")
e = F("e")

b.p = g
b.q = a
g.r = m
g.x = e
a.w = g
a.r = e
m.v = b
m.p = e
f.q = e
f.y = e
e.z = b
assert a.r.z.q.txt == "a"