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

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

g = A("g")
d = B("d")
n = B("n")
h = A("h")
j = A("j")
i = A("i")
b = A("b")
c = A("c")
f = A("f")

g.x = n
g.t = f
d.s = i
n.s = j
h.x = n
h.t = b
j.x = d
j.t = b
i.x = n
i.t = c
b.x = d
b.t = g
c.x = d
c.t = i
f.x = d
f.t = c
assert d.s.x.s.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.t: A = None
        self.txt = txt

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

g = A("g")
d = B("d")
n = B("n")
h = A("h")
j = A("j")
i = A("i")
b = A("b")
c = A("c")
f = A("f")

g.x = n
g.t = f
d.s = i
n.s = j
h.x = n
h.t = b
j.x = d
j.t = b
i.x = n
i.t = c
b.x = d
b.t = g
c.x = d
c.t = i
f.x = d
f.t = c
assert d.s.x.s.t.x.txt == "d"