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

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

class C:
    def __init__(self, txt: str):
        self.s: B = None
        self.x: D = None
        self.t: D = None
        self.y: B = None
        self.txt = txt

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

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

b.q = e
k.q = b
k.t = b
k.s = c
c.s = k
c.y = k
c.x = e
c.t = e
e.r = b
assert b.q.r.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.q: A = None
        self.t: A = None
        self.s: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.s: B = None
        self.x: D = None
        self.t: D = None
        self.y: B = None
        self.txt = txt

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

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

b.q = e
k.q = b
k.t = b
k.s = c
c.s = k
c.y = k
c.x = e
c.t = e
e.r = b
assert b.q.r.q.r.txt == "b"