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

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

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

b = A("b")
f = B("f")
n = C("n")
a = B("a")
d = C("d")
g = A("g")

b.t = g
b.w = g
b.q = f
f.r = a
n.s = d
a.r = f
d.s = n
g.t = b
g.w = b
g.q = f
assert b.q.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.w: A = None
        self.q: B = None
        self.txt = txt

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

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

b = A("b")
f = B("f")
n = C("n")
a = B("a")
d = C("d")
g = A("g")

b.t = g
b.w = g
b.q = f
f.r = a
n.s = d
a.r = f
d.s = n
g.t = b
g.w = b
g.q = f
assert b.q.r.r.r.txt == "a"