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

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

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

g = A("g")
k = B("k")
e = C("e")
i = B("i")
b = A("b")
h = C("h")

g.q = b
k.p = g
k.t = g
k.q = h
e.s = b
i.p = g
i.q = e
i.t = b
b.q = g
h.s = b
assert i.t.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

g = A("g")
k = B("k")
e = C("e")
i = B("i")
b = A("b")
h = C("h")

g.q = b
k.p = g
k.t = g
k.q = h
e.s = b
i.p = g
i.q = e
i.t = b
b.q = g
h.s = b
assert i.t.q.q.q.q.q.txt == "g"