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

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

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

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

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

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

h.x = l
l.s = b
l.y = b
b.s = l
b.y = l
g.s = b
g.y = l
assert g.y.s.s.s.txt == "b"