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

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

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

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

b.v = h
d.w = c
d.t = b
d.r = h
c.o = g
g.w = c
g.t = b
g.r = h
e.w = c
e.t = b
e.r = b
i.w = c
i.t = h
i.r = h
h.v = b
assert g.r.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

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

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

b.v = h
d.w = c
d.t = b
d.r = h
c.o = g
g.w = c
g.t = b
g.r = h
e.w = c
e.t = b
e.r = b
i.w = c
i.t = h
i.r = h
h.v = b
assert g.r.v.v.v.txt == "b"