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

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

h = A("h")
f = B("f")
c = A("c")
n = B("n")
g = B("g")

h.w = c
h.y = c
f.q = c
f.w = h
c.w = h
c.y = h
n.q = h
n.w = c
g.q = c
g.w = c
assert g.w.y.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.y: A = None
        self.txt = txt

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

h = A("h")
f = B("f")
c = A("c")
n = B("n")
g = B("g")

h.w = c
h.y = c
f.q = c
f.w = h
c.w = h
c.y = h
n.q = h
n.w = c
g.q = c
g.w = c
assert g.w.y.w.y.txt == "h"