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

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

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

b = A("b")
e = B("e")
g = C("g")
h = B("h")
l = C("l")

b.x = g
e.r = b
e.x = l
g.x = e
g.y = e
h.r = b
h.x = g
l.x = e
l.y = e
assert b.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

b = A("b")
e = B("e")
g = C("g")
h = B("h")
l = C("l")

b.x = g
e.r = b
e.x = l
g.x = e
g.y = e
h.r = b
h.x = g
l.x = e
l.y = e
assert b.x.x.x.x.txt == "e"