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

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

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

j = A("j")
b = B("b")
h = C("h")
d = C("d")
i = C("i")
c = B("c")

j.q = c
j.p = c
b.t = d
h.q = j
d.q = j
i.q = j
c.t = h
assert b.t.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: B = None
        self.txt = txt

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

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

j = A("j")
b = B("b")
h = C("h")
d = C("d")
i = C("i")
c = B("c")

j.q = c
j.p = c
b.t = d
h.q = j
d.q = j
i.q = j
c.t = h
assert b.t.q.q.txt == "c"