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

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

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

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

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

b.q = c
k.y = m
k.v = b
k.p = e
g.v = e
g.t = b
c.o = m
c.r = m
c.w = b
m.o = c
m.r = c
m.w = b
e.v = g
e.t = b
assert k.v.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

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

b.q = c
k.y = m
k.v = b
k.p = e
g.v = e
g.t = b
c.o = m
c.r = m
c.w = b
m.o = c
m.r = c
m.w = b
e.v = g
e.t = b
assert k.v.q.r.txt == "m"