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

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

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

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

g = A("g")
a = B("a")
n = C("n")
c = D("c")
f = C("f")

g.r = a
a.w = n
a.r = c
n.q = a
n.x = c
n.v = c
c.x = g
f.q = a
f.x = c
f.v = c
assert a.r.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

g = A("g")
a = B("a")
n = C("n")
c = D("c")
f = C("f")

g.r = a
a.w = n
a.r = c
n.q = a
n.x = c
n.v = c
c.x = g
f.q = a
f.x = c
f.v = c
assert a.r.x.r.txt == "a"