class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.r: D = None
        self.s: B = None
        self.u: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

e = A("e")
g = B("g")
c = C("c")
a = D("a")
b = B("b")

e.q = c
e.u = c
e.r = a
e.s = g
g.v = c
g.r = a
g.w = b
c.v = e
a.p = g
b.v = c
b.r = a
b.w = g
assert b.v.v.q.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.r: D = None
        self.s: B = None
        self.u: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

e = A("e")
g = B("g")
c = C("c")
a = D("a")
b = B("b")

e.q = c
e.u = c
e.r = a
e.s = g
g.v = c
g.r = a
g.w = b
c.v = e
a.p = g
b.v = c
b.r = a
b.w = g
assert b.v.v.q.v.r.txt == "a"