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

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

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

g = A("g")
m = B("m")
d = C("d")
h = B("h")

g.r = h
m.q = h
d.p = g
d.r = g
h.q = m
assert m.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
d = C("d")
h = B("h")

g.r = h
m.q = h
d.p = g
d.r = g
h.q = m
assert m.q.q.q.q.txt == "m"