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

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

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

c = A("c")
e = B("e")
b = C("b")
m = A("m")
n = B("n")
d = C("d")

c.q = m
e.s = n
b.t = c
b.r = m
m.q = c
n.s = e
d.t = m
d.r = m
assert e.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

c = A("c")
e = B("e")
b = C("b")
m = A("m")
n = B("n")
d = C("d")

c.q = m
e.s = n
b.t = c
b.r = m
m.q = c
n.s = e
d.t = m
d.r = m
assert e.s.s.s.s.txt == "e"